Hey folks,
I'll be the first to admit that the last time I did any serious C programming was over a decade ago at uni. Up until today, my work with C has been basic maintenance and minor code changes.
Anyway, I'm running into a segmentation fault that just has me reviving my days in the Navy with cursing.
Here's the function causing the problem:
The bit in particular is the last j++ statement. It's driving me spare. If I just put a printf in there with the strcmp outcome, the ENTIRE program runs fine. If I put anything except the j++ line in, the program runs fine (though the function returns a number one less than the intended amount).
After figuring out my char memory problems, this one has me wanting a stiff drink.
Any help greatly appreciated.
I'll be the first to admit that the last time I did any serious C programming was over a decade ago at uni. Up until today, my work with C has been basic maintenance and minor code changes.
Anyway, I'm running into a segmentation fault that just has me reviving my days in the Navy with cursing.
Here's the function causing the problem:
Code:
int dir_parts(char *dir_name){
int i;
int j;
char c[2];
j = 0;
for (i = 0; i < strlen(dir_name); i++){
strcpy(c, getsub(dir_name, i, i));
if (strcmp(c, "/") == 0){
j++;
}
}
if (strcmp(c, "/") != 0){
j++;
}
return(j);
}
The bit in particular is the last j++ statement. It's driving me spare. If I just put a printf in there with the strcmp outcome, the ENTIRE program runs fine. If I put anything except the j++ line in, the program runs fine (though the function returns a number one less than the intended amount).
After figuring out my char memory problems, this one has me wanting a stiff drink.
Any help greatly appreciated.