Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Compiled but not running

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Hi, I'm sort of new at this. I wrote a program. it compiled correctly but when i try and run it, it gives me an error message that says: memory fault(coredump) Does anyone know what that means and how to fix it?
 
Pls post your code for better understanding of this problem and specify the compiler u r using.

regards,
SwapSawes-)
 
It seems that in C the memory fails are the most common errors. Some common cases when memory fails:
Incorrect arrays using. For example:
Code:
int a[10];
a[10]=5; /* Error - Out of range */
Incorrect strings using:
Code:
char* a = "ABC";
strcpy (a, "ABCDEF"); /* No memory allocated for such long string - Error*/
Such constructions:
Code:
char* b = "ABC";
char* a = b;
/* Error if we'll destroy 'b' and try to write something into 'a' */
Returning pointer to local variable, incorrect scanf() using, many, many, many other errors...

SwapSawe is right: You should post your code...
 
>char* a = "ABC";
>strcpy (a, "ABCDEF"); /* No memory allocated for such long string - Error*/

Actually, the error here is that writing anything into a results in undefined behavior.

So, doing this would also be an error:

char *a="ABC";
strcpy(a,"ABC");

a points to a string literal that was possibly stored in read-only memory. It's analogous to doing this:

strcpy("ABC","ABC");

On the other hand, if a were declared as an array, writing into it would be Ok, providing that you didn't write too many characters:

char a[]="ABC";
strcpy(a,"abc"); /* ok */
strcpy(a,"abcdefgh"); /* not ok, string too long */
Russ
bobbitts@hotmail.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top