FW: Re: [ale] C and segmentation fault

c_fowler at hotmail.com c_fowler at hotmail.com
Thu Jul 17 13:58:08 EDT 1997


How can I concatenate thos two strings together?

Thanks,
Christopher Fowler 
-----FW: <33CE13B5.67A3FC82 at wiencko.com>-----

Date: Thu, 17 Jul 1997 08:44:38 -0400
Sender: owner-ale at cc.gatech.edu
 From: Tom Wiencko <tew at wiencko.com>
To: c_fowler at hotmail.com
Subject: Re: [ale] C and segmentation fault
Cc: ale at cc.gatech.edu

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.

--------------End of forwarded message-------------------------

----------------------------------
E-Mail:  c_fowler at hotmail.com
Date: 17-Jul-97
Time: 13:58:08

This message was sent by XFMail
----------------------------------






More information about the Ale mailing list