I am using CrossWorks, and can't get sscanf to work. It returns a value
that indicates that the parameters were scanned, but the values it puts
in them appear random. For any given string it comes up with the same
values, but they don't appear to be related to the string
I've seen this happen before and just used strtol instead, as a work
around. Doesn't look like there is an atof or strtod available, so
I'd
really rather use a sscanf with %f, especially since there are several
variable length fields with delimiters.
Any 'gotchas' I need to be aware of when using sscanf on
CrossStudio
with the MSP430?
Thanks,
Miles
PS: I apologize if I already asked this question. I searched the
archives and my sent mail, and don't see mention of it, but I know I
asked *someone* at some time, just don't remember who or when. :D
question on sscanf
Started by ●September 10, 2004
Reply by ●September 10, 20042004-09-10
> I am using CrossWorks, and can't get sscanf
to work.
The IAR compiler (some non-current version) doesn't support sscanf()
with %f either. It was a big letdown when I learned that the hard
way.
There must be some magical reason why the compilers don't support
it. Like you, I settled for manual string parsing and a call to atof
() but apparently you don't even have atof(). Might be time for a
compiler change. :(
JJS
The IAR compiler (some non-current version) doesn't support sscanf()
with %f either. It was a big letdown when I learned that the hard
way.
There must be some magical reason why the compilers don't support
it. Like you, I settled for manual string parsing and a call to atof
() but apparently you don't even have atof(). Might be time for a
compiler change. :(
JJS
Reply by ●September 10, 20042004-09-10
Reply by ●September 10, 20042004-09-10
Reply by ●September 10, 20042004-09-10
Miles,
The return value of scanf is the number of items successfully scanned.
You need to set up the IDE to link in the correct version of scanf()
i.e. enable floating point I/O in the project, otherwise %f won't work.
I seem to remember a problem in the scanf code at one point which caused
the problem you see. This is now fixed, and we'll be releasing a new
version of the IDE just after I've written the last pieces of
documentation.
-- Paul.
The return value of scanf is the number of items successfully scanned.
You need to set up the IDE to link in the correct version of scanf()
i.e. enable floating point I/O in the project, otherwise %f won't work.
I seem to remember a problem in the scanf code at one point which caused
the problem you see. This is now fixed, and we'll be releasing a new
version of the IDE just after I've written the last pieces of
documentation.
-- Paul.
Reply by ●September 10, 20042004-09-10
John,
> > I am using CrossWorks, and can't get sscanf to work.
>
> The IAR compiler (some non-current version) doesn't support
> sscanf() with %f either. It was a big letdown when I learned
> that the hard way.
You need to link the version of scanf in that supports floating point...
> There must be some magical reason why the compilers don't
> support it.
Correct. You might just want to scan integers, never need %f, and want
to fit it into a small device. For this, you want an integer-only
version of scanf. If you need the full-blown thing, then link in the
full-blown scanf including character class support, long lomg, floating
point, the works.
> Like you, I settled for manual string parsing
> and a call to atof
> () but apparently you don't even have atof(). Might be time
> for a compiler change. :(
Atof is now part of the CrossWorks library.
-- Paul.
> > I am using CrossWorks, and can't get sscanf to work.
>
> The IAR compiler (some non-current version) doesn't support
> sscanf() with %f either. It was a big letdown when I learned
> that the hard way.
You need to link the version of scanf in that supports floating point...
> There must be some magical reason why the compilers don't
> support it.
Correct. You might just want to scan integers, never need %f, and want
to fit it into a small device. For this, you want an integer-only
version of scanf. If you need the full-blown thing, then link in the
full-blown scanf including character class support, long lomg, floating
point, the works.
> Like you, I settled for manual string parsing
> and a call to atof
> () but apparently you don't even have atof(). Might be time
> for a compiler change. :(
Atof is now part of the CrossWorks library.
-- Paul.
Reply by ●September 10, 20042004-09-10
To use sscanf in the IAR compiler you must change the configuration the the
XLink control file from the default of:
-e_medium_read=_formatted_read
The default allows sscanf but does not allow floating point numbers.
To use the full ANSI version allowing floating point number remove the line in your .xcl file.
Ted
-e_medium_read=_formatted_read
The default allows sscanf but does not allow floating point numbers.
To use the full ANSI version allowing floating point number remove the line in your .xcl file.
Ted
Reply by ●September 15, 20042004-09-15