Hello. I have been kicking myself for a while now and I was wondering if anyone could please help me. My code is:

char fname[FNAME_LEN] = "blah"

FILE * fp = fopen(fname, "r");

char line[BUF_LEN];

while( fscanf(fp, "%s", line) != EOF )
{
   double x = atof(strtok(line, "|") );
   unsigned long y = atol(strtok(NULL, "\0"));

   printf("%f - %d\n", x, y);
}
fclose(fp)

my input stream format is:

123.45|12345

for every x value, the program prints -0.00000 but all the y values print correctly. Also, if I don't use atof and just print x as a string, I get the correct output.

Any help would be greatly appreciated.

Did you include stdlib.h?

ahhhhhhhhhhhhhh yes i forgot to include it!!! Thanks so much for your help

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.