sscanf function fails CW 5.9 IDE

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

sscanf function fails CW 5.9 IDE

ソリューションへジャンプ
1,047件の閲覧回数
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.


  

ラベル(1)
タグ(1)
0 件の賞賛
返信
1 解決策
849件の閲覧回数
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 件の賞賛
返信
3 返答(返信)
849件の閲覧回数
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 件の賞賛
返信
850件の閲覧回数
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 件の賞賛
返信
849件の閲覧回数
CrasyCat
Specialist III

Hello

 

Additional question/note from CompilerGuru answer.

 

Make sure you include stdio.h in your project

 

CrasyCat

0 件の賞賛
返信