[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[ale] C and segmentation fault
- Subject: [ale] C and segmentation fault
- From: tew at wiencko.com (Tom Wiencko)
- Date: Thu, 17 Jul 1997 08:44:38 -0400
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.