sscanf function fails CW 5.9 IDE

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

sscanf function fails CW 5.9 IDE

Jump to solution
1,012 Views
jmborchers
Contributor I

The function  vsscanf(LIBDEF_ConstStringPtr ps, LIBDEF_ConstStringPtr format, va_list args) in the scanf.c library always fails.

 

Input:

int x;

int result;

result=sscanf("123","%d",&x);

 

result always returns 0 and x never has the value 123.

This is because:

 

            if (*s++ == *format++) { /*lint !e931 the expression is safe */

in the function vsscanf line can never be true. The code then jumps to inputFailure

 

Why would the input string be compared against the format string? It doesn't seem to make any sense.


  

Labels (1)
Tags (1)
0 Kudos
1 Solution
814 Views
CompilerGuru
NXP Employee
NXP Employee

First please always mention what CPU/derivative you are targeting, this board is for so different chips like a RS08 (does not have a stack) up to a Coldfire V1 (32 bit registers).

 

I'm guessing that there must be something wrong with your setup, for example not enought stack space, using the a library which is incompatible with the provided options, issues with the memory layout, ....

 

The line you are quoting is to match direct input (think of sscanf("Hello", "Hello")), so the code apparently did not parse the % first.

 

I would suggest:

- start with a fresh, wizard generated project.

- make sure you have enough stack space

- copy/paste your simple sscanf code into it

- make sure it compiles without warnings (implicit parameter declarations)

- if that fails, zip it and post the project it here.

 

Daniel

 

BTW: IDE 5.9 refers to the editor/development environment. Really does not narrow the possibilities down.

View solution in original post

0 Kudos
3 Replies
814 Views
Lundin
Senior Contributor IV

Why are you using sscanf() on a 8- or 16-bit microcontroller? I can't come up with any reason why one would do that.

0 Kudos
815 Views
CompilerGuru
NXP Employee
NXP Employee

First please always mention what CPU/derivative you are targeting, this board is for so different chips like a RS08 (does not have a stack) up to a Coldfire V1 (32 bit registers).

 

I'm guessing that there must be something wrong with your setup, for example not enought stack space, using the a library which is incompatible with the provided options, issues with the memory layout, ....

 

The line you are quoting is to match direct input (think of sscanf("Hello", "Hello")), so the code apparently did not parse the % first.

 

I would suggest:

- start with a fresh, wizard generated project.

- make sure you have enough stack space

- copy/paste your simple sscanf code into it

- make sure it compiles without warnings (implicit parameter declarations)

- if that fails, zip it and post the project it here.

 

Daniel

 

BTW: IDE 5.9 refers to the editor/development environment. Really does not narrow the possibilities down.

0 Kudos
814 Views
CrasyCat
Specialist III

Hello

 

Additional question/note from CompilerGuru answer.

 

Make sure you include stdio.h in your project

 

CrasyCat

0 Kudos