sscanf segmentation fault
Hi all,
I'm having a segmentation fault that I don't understand. The program compiles and runs just fine on any number of different Macs I've tried it on (OSX 10.5, and 10.6), but when I tried moving it to a linux cluster, I'm getting a segmentation error right here.
Code:
float fprime= 0;
char * pch;
.... intervening code ....
while (fgets(buf, sizeof(buf), fp)!=NULL)
{
pch = strtok(buf, ",");
while (pch != NULL)
{
printf("before sscanf\n");
sscanf(pch, "%f", &fprime);
printf("after sscanf\n");
f[k]= fprime;
printf("is it here\n");
pch= strtok(NULL, ",");
printf("checking\n");
k++;
}
}
You can see from the code where I've put in printf statements to try and figure out exactly when the segmentation fault is occuring, and it happens right at the sscanf. strtok returns a pointer of type char to the last token found in the string, so I don't think it's because there's a problem with pch, but maybe I'm wrong?
I'd appreciate any help and/or suggestions.
Brad