CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 14 of 14

Threaded View

  1. #1
    Join Date
    Jun 2004
    Posts
    47

    fscanf gives unexpected data

    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 ------------

    Code:
    char idNum[30];
    // here I fill the array
    FILE * fout = fopen("data.txt","w");
    fprintf(fout,"Id num %s\n",idNum);
    fclose(fout);
    ----- reading in --------------
    later in my program I read in the data I wrote out in a loop
    testing each id for a match
    Code:
    char idNum[30];
    FILE * fin = fopen("data.txt","r");
    fscanf(fin,"Id num %s\n",idNum);
    if(strcmp(idNum, desiredNum))
    ...
    fclose(fin);
    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.

    Is there anything which could interfere with fscanf (and fread, I tried it and got the same result)? I am totally baffled.
    Last edited by imposterrific; June 28th, 2004 at 06:13 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured