[ale] C and segmentation fault
Tom Wiencko
tew at wiencko.com
Thu Jul 17 08:44:38 EDT 1997
c_fowler at hotmail.com wrote:
>
> Why when I run this proggie do I get a segmentation fault?
>
#include<stdio.h>
#include<string.h>
main()
{
char *s1;
char *s2;
s1="S1";
s2="S2";
s2=strcat(s1,s2);
return 0;
}
Very simple. The line "s2=strcat(s1,s2)" is causing strcat to
try to physically overwrite the read-only memory space where "S2"
lives. When you assigned s2="S2" you are pointing s2 to an address
in an area where only constants are supposed to live. You cannot
modify things in that address space.
-Tom
----------------------------------------------------------------------
Tom Wiencko tew at wiencko.com
President - Wiencko & Associates, Inc.
More information about the Ale
mailing list