Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C++ (http://www.go4expert.com/forums/cpp/)
-   -   [c++] <stdio.h> fscanf and fprintf in text mode with a object double (http://www.go4expert.com/forums/cpp-stdioh-fscanf-fprintf-text-mode-t2451/)

zawart 6Jan2007 02:57

[c++] <stdio.h> fscanf and fprintf in text mode with a object double
 
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:

zawart 6Jan2007 03:20

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

DaWei 6Jan2007 03:22

Re: [c++] <stdio.h> fscanf and fprintf in text mode with a object double
 
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?


All times are GMT +5.5. The time now is 15:40.