Question:
help with segfault?
2007-11-13 18:20:05 UTC
Please help. I keep getting a segfault and don't know how to fix the code.

bool a=false;
char* t=(char*)malloc(sizeof(char)*BUFFER_LENGTH);
char *n;
do{
printf("Enter text to be converted. (1 to quit). \n");

text = fgets(t,BUFFER_LENGTH,stdin);

n = strchr(t,'\n');

if(n)
n[0]='\0';

if(strcmp(t,"1")==0)
a=false;
else{
process (t);
a=true;
}
}while(a);
free(t);
Three answers:
Ryan
2007-11-13 19:07:02 UTC
If you open the dump in gdb, and use the where command, you should be able to narrow down what's going on.
Dark-River
2007-11-13 18:26:33 UTC
Some of the code was clipped so it is difficult to tell.



However, 'text' isn't defined anywhere.
2007-11-13 18:22:50 UTC
google it..

google can help you with almost anything.

just say segfault and copy what they have on a website.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...