Results 1 to 2 of 2

Thread: wrong type?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 2000
    Posts
    183

    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);
    }

  2. #2
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    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
  •  



Click Here to Expand Forum to Full Width