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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

segmentation fault with gcc 1

Status
Not open for further replies.

bwysocki

Programmer
Sep 19, 2001
38
US
I'm porting some C code from SCO over to SuSE Linux. GCC is throwing me a segmentation fault when I run the code..

(Calling function)

myfunc("\n");
.
.

int myfunc(st)
char *st;
{
int org_len;

org_len = strlen(st);

if( st[org_len-1] == '\n' )
{
/* note: org_len is 1 */
st[org_len - 1] = '\0'; /* segmentation fault */
}
.
.
}

Apparently gcc is more picky than the old SCO compiler. Is it that I'm passing in a string to myfunc instead of a variable that has allocated memory?

Thanks,

Bob
 
String literals should be considered read-only memory.
Code:
myfunc([red]"\n"[/red]);
Don't try to overwrite read-only memory; declare a writeable string and try that.
 
I figured that had something to do with it. Thanks!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top