sscanf function fails CW 5.9 IDE

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

sscanf function fails CW 5.9 IDE

跳至解决方案
1,373 次查看
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 解答
1,175 次查看
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 回复数
1,175 次查看
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 项奖励
回复
1,176 次查看
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 项奖励
回复
1,175 次查看
CrasyCat
Specialist III

Hello

 

Additional question/note from CompilerGuru answer.

 

Make sure you include stdio.h in your project

 

CrasyCat

0 项奖励
回复