带有%d的scanf不会停止输入

时间:2021-07-21 21:13:53

I have a small program that uses scanf to block the program :

我有一个小程序,使用scanf来阻止程序:

int main (void)
{
    stdout = stdin = &uart_str;
    int i = 0;

    while(1) {
        scanf("%d",&i);
        readMeasurement();
    }

The problem that I have is that the program is not stopping at the scanf. I'm using Atmel Studio and the UART for the input and output.

我遇到的问题是程序没有在scanf停止。我正在使用Atmel Studio和UART进行输入和输出。

Any idea how I can solve this ?

知道如何解决这个问题吗?

1 个解决方案

#1


I'm not sure but try this below

我不确定,但尝试下面这个

edit from scanf("%d",&i); to scanf(" %d",&i);

从scanf编辑(“%d”,&i);到scanf(“%d”,&i);

(insert space in front of %d )

(在%d前插入空格)

#1


I'm not sure but try this below

我不确定,但尝试下面这个

edit from scanf("%d",&i); to scanf(" %d",&i);

从scanf编辑(“%d”,&i);到scanf(“%d”,&i);

(insert space in front of %d )

(在%d前插入空格)