[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[ale] C and segmentation fault
- Subject: [ale] C and segmentation fault
- From: c_fowler at hotmail.com (c_fowler at hotmail.com)
- Date: Thu, 17 Jul 1997 13:50:07 -0400 (EDT)
How can I join string S2 and S1 ont S1 so that s1 looks like 'S1S2'.
Thanks,
Christopher Fowler
On 17-Jul-97 Tom Wiencko wrote:
>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.
----------------------------------
E-Mail: c_fowler at hotmail.com
Date: 17-Jul-97
Time: 13:50:07
This message was sent by XFMail
----------------------------------