I am using strod() to convert a string - "1 QA" into an index and a label. So this would be an index of 1 and a label of QA. Here is the program.
int main (void)
int BUFSIZE = 100;
int i, Index;
char * P, * NewLine;
Fp = fopen("filename","r");
printf("Not able to open file!
for (i=1; fgets(Buffer,BUFSIZ,Fp) ; i++)
Index = strtod(Buffer,&P);
if (P == Buffer)
printf("Line %d: missing index for label %s", i, Buffer);
if (Index < 0 || Index > 100)
printf("Line %d: Bad index %d for label %s",
i, Index, Buffer);
NewLine = strchr(P,'
*NewLine = '';
printf("Label is %s index is %d
", P, Index);
The strange part is that it works fine as a stand alone program, but when used as part of an algorithm set for a system, strod() returns a bad index...
Line 1: Bad index -268450352 for label 1 QA
This is using the same exact same input file in both cases. Why would it work sometimes and not others?