|
-
Feb 25th, 2002, 11:43 PM
#1
Thread Starter
Addicted Member
wrong type?
am i using fscanf wrong, or using the wrong types? I can't get the precision required to capture these numbers, it always chops off numbers, here is what it is reading in:
207.23.53.200 1648.696 0.43913716114060686 1
LoadLine(){
FILE *input;
char cIp [12];
long float iRtt, iPackloss, iUtil;
int iPacketloss;
input = fopen("sampledata1.txt","r");
fscanf(input,"%s %lf %lf %i",&cIp, &iRtt, &iUtil, &iPackloss);
}
-
Feb 27th, 2002, 01:57 PM
#2
input = fopen("sampledata1.txt","r");
this should be "rt" or "rb" on DOS/windows
fscanf(input,"%s %lf %lf %i",&cIp, &iRtt, &iUtil, &iPackloss);
%s expects char* to be passed, if you declare cIp as
char[12];
(you actually need 16: 12 numbers, 3 dots and a NUL)
then to get char* you simply write cIp, or &cIp[0], but not &cIp.
Is "long float" a valid type? I think the compiler just ignores the long and create a simple float, which would be the reason why it cuts off numbers: the precision of a float is not high enough to hold 0.43913716114060686 (I think not even double can handle this)
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|