sscanf and decimals

This is a discussion on sscanf and decimals within the C++ Programming forums, part of the General Programming Boards category; Hey, I'm using sscanf to read from buffer into int and double variables, but it doesn't recognise the decimal numbers. ...

  1. #1
    Registered User
    Join Date
    May 2005
    Location
    Toronto, Canada
    Posts
    257

    sscanf and decimals

    Hey,
    I'm using sscanf to read from buffer into int and double variables, but it doesn't recognise the decimal numbers.
    Code:
    fgets(line, sizeof line, inp);
    check = (sscanf(line, "%s %d %d %f %d %d %f %f", dl.Param, &dl.Label,
                       &dl.SFactor, &dl.SigBits, &dl.Bit30, &dl.Bit31, &dl.Max, &dl.Min)); 
    
    // and
    
    	CString Param;
    	int Label, SigBits, Bit30, Bit31;
    	double 	SFactor, Max, Min;
    if I have line = " FUELFLOW= 160 0.5 16 1 1"

    check returns 3 when I'd like it to return 6. How can I make it read in the 0.5 all together into SFactor?
    Last edited by earth_angel; 08-15-2005 at 10:32 AM.
    Everything is relative...

  2. #2
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    Use the directive(s) that correctly corresopnd to the data type(s).
    Quote Originally Posted by earth_angel
    Code:
    check = (sscanf(line, "%s %d %d %f %d %d %f %f", dl.Param, &dl.Label,
                       &dl.SFactor, &dl.SigBits, &dl.Bit30, &dl.Bit31, &dl.Max, &dl.Min));
    if I have line = " FUELFLOW= 160 0.5 16 1 1"
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  3. #3
    Registered User
    Join Date
    May 2005
    Location
    Toronto, Canada
    Posts
    257
    and I thought there was something wrong with the way sscanf works. I've spent way too much time on this project, and I don't pay attention to the details as much as I should anymore.

    Sorry for the stupidity.

    Thanks,

    AS.
    Everything is relative...

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21