C seg fault
This code segfaults on the first strtok:
Code:
int mkdirp(char* file) |
You can't use strtok() on string constants according to the man page:
Code:
BUGS Code:
int main(void) Code:
int main(void) |
still fails - this is now the relevant part of my main:
Code:
char* newdir="newdir"; |
This:
Code:
char* newdir="newdir"; Code:
char dirname[] = "newdir"; It's still segfaulting for you because you're still using a string constant. Use my suggestion and it will work fine. |
really? oh well - i just gave up and wrote it myself (turns out i forgot something and it was easier to write it myself)
thanks. |
Yeah, string constants such as "newdir" go into read-only memory. So when you do char *name = "newdir"; you're just creating a pointer that points to read-only memory, but when you do char name[] = "newdir"; you're creating an array and copying the contents of "newdir" into the array. The memory for the array is not in read-only memory.
|
All times are GMT -5. The time now is 08:19 PM. |