sscanf question

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 
564件の閲覧回数
asier
Contributor III

Hi,

I'm working with LPC804 and MCUXpresso IDE.

I'm trying to do work sscanf but no way.

My example is the following:

char buff[] = "12";
int i;
sscanf(buff,"%d",&i);

if (i == 12){
GPIO_PinWrite(BOARD_INITPINS_BLOQ_GPIO,BOARD_INITPINS_BLOQ_PORT,BOARD_INITPINS_BLOQ_PIN, 1);
}

Any idea what is wrong? 

Thanks,

Asier.

0 件の賞賛
返信
1 解決策
296件の閲覧回数
asier
Contributor III

Hi HangZhang,

My problem was that I was doing uint16_t i; instead int i;.

I don't know why but when using uint16_t i; sscanf stucks.

Thank you for your time,

BR

Asier.

元の投稿で解決策を見る

4 返答(返信)
539件の閲覧回数
HangZhang
NXP Employee
NXP Employee

Hi @asier 

When you use this pin, please initialize the configuration for this pin.

 

Hope this will help you.

BR

Hang

0 件の賞賛
返信
368件の閲覧回数
asier
Contributor III

Hi HangZhang,

The pin is correctly initialized and it works fine.

The issue is not with "GPIO_PinWrite" instruction, but with "sscanf".

"i" does not get 12 value after executing "sscanf(buff,"%d",&i);" code line.

What is wrong when using sscanf in our example?

Thank you,

Asier.

0 件の賞賛
返信
352件の閲覧回数
HangZhang
NXP Employee
NXP Employee

Hi @asier 

I refer to your code, i can get 12 value after executing "sscanf(buff,"%d",&i);" code line.

HangZhang_0-1724726855044.png

I share my code with you.

BR

Hang

0 件の賞賛
返信
297件の閲覧回数
asier
Contributor III

Hi HangZhang,

My problem was that I was doing uint16_t i; instead int i;.

I don't know why but when using uint16_t i; sscanf stucks.

Thank you for your time,

BR

Asier.