I'm using fscanf to read data out of a file which I created by writing to the file eith fprintf. Here is an example of my code
----- writing out ------------
----- reading in --------------Code:char idNum[30]; // here I fill the array FILE * fout = fopen("data.txt","w"); fprintf(fout,"Id num %s\n",idNum); fclose(fout);
later in my program I read in the data I wrote out in a loop
testing each id for a match
Right now I have three files to which I write the same id number each time. The id number is 97808859948941785921. The first two files I read will read in the Id num correctly, but on the third file and always the third file the id number read in is 0656663696113801664 even though when I open the file and read it myself it says 97808859948941785921. I have other functions which read the id with the same code as above just cut and pasted and it reads correctly.Code:char idNum[30]; FILE * fin = fopen("data.txt","r"); fscanf(fin,"Id num %s\n",idNum); if(strcmp(idNum, desiredNum)) ... fclose(fin);
Is there anything which could interfere with fscanf (and fread, I tried it and got the same result)? I am totally baffled.




Reply With Quote