[c++] <stdio.h> fscanf and fprintf in text mode with a object double

Discussion in 'C++' started by zawart, Jan 5, 2007.

  1. zawart

    zawart New Member

    Joined:
    Jan 5, 2007
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    Code:
    #include <conio.h>
    #include <stdio.h>
    #include <string.h>
    
    typedef struct
    {
    char surname[20];
    double somenumber;
    }personnel;
    personnel jack;
    int main()
    {
    
    FILE *stream;
    jack.somenumber=87021506119; //Here I changed the first time the value
    strcpy(jack.surname,"Mcgyver");
    
    stream=fopen("c:\\personnel.txt","wt");
    fprintf(stream,"%s\t%0.lf",jack.surname,jack.somenumber);
    fclose(stream);
    
    jack.somenumber=87021506000;    // Here I changed the second time the value
    stream=fopen("c:\\personnel.txt","rt");
    fscanf(stream,"%s\t%0.lf",jack.surname,&jack.somenumber);
    fclose(stream);
    
    printf("%s\t%.0f",jack.surname,jack.somenumber); //Here I get '87021506000' and this is not the value that should be here :/
    getch();
    }
    I really don't know why it's not working...... Please HELP me ! :confused:
     
  2. zawart

    zawart New Member

    Joined:
    Jan 5, 2007
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
  3. DaWei

    DaWei New Member

    Joined:
    Dec 6, 2006
    Messages:
    835
    Likes Received:
    5
    Trophy Points:
    0
    Occupation:
    Semi-retired EE
    Location:
    Texan now in Central NY
    Home Page:
    http://www.daweidesigns.com
    You need to learn how to post a question. Since we're only mind readers on the second Tuesday of each week, you should TELL us things. How is it not working? How is it not meeting your expectations? Do you have compiler errors? Do you have run-time errors? What is your OS? Your implementation? Your compiler? On what lines to the errors, if any, occur?

    That said, let me ask YOU a question. Why are you using C library functions in C++? Even if they work? Bite the bullet. Get off the fence. Write C or write C++. Just make up your mind.

    That said, also, I have not looked at your code. I'm sure I could figure out what is wrong, if I spent the time. I don't want to spend the time if YOU don't want to spend the time. Fair enough?
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice