Re: sscanf trouble

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 25 January 2011 11:09, Jonathan Andrews wrote:
> Hi people.
>
> Can anyone help with what should be a simple problem. I have some text
> in the following form. Its a temperature reading from a wireless sensor,
> the format is T<sensor number>=<float ish> <TAB><TAB><Two digit ascii
> checksum>
>
> T1=18.0<TAB><TAB>XX\n\r
>
> Some examples:
>
>        T1=-11.5        EA
>        T1=24.0         9D
>
> Im trying to convert this string into a sensor ID, a floating point
> reading and a checksum as 3 variables using sscanf
>
> sscanf(line,"T%d=%f\t\t%X",&sensorid,&temperature,&checksum);
>
> No amount of variations on a theme seem to give me an entire decode
> here, seems the equals seems to screw things up.  Anyone any ideas how I
> can make this work?
>
> Thanks for any advice,
> Jon

This is just a general C question, unrelated to gcc, so there are more
relevant places to ask.
Asking C language questions on a compiler list is like asking a car
manufacturer for directions: gcc is just a tool you use to compile C.
Anyway ...

All you've said is something is screwed up, so it's no obvious what is
happening and why it doesn't match what you expect.  The sscanf call
should work, as long as 'line' really does match the format you
expect, sensorid is an int, checksum is an unsigned int, and
temperature is a float (not a double.)



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux