c pointer Segmentation fault
void get(){
char fileNameBuf[10];
int i=0;
if (*buf=='/') {
*buf++;
while (*buf!=' ') {
fileNameBuf[i]=*buf;
*buf++;
i++;
printf("%d\n",i);
}
}
}
*buf points to string "/index.html HTTP/1.0". This while loop stores the
character that *buf points to until *buf points to a space. So fileNameBuf
should store the string "index.html". i indicates the number of times the
while loop looped which should be 10. But when i run this code, i = 381
instead and Segmentation fault (core dumped) occurs, what is wrong with
the code and how do i fix it?
No comments:
Post a Comment