我正在尝试将用户输入流中的值分配给变量 M 和 N。如果我指定 int 类型的 M 和 N,我可以让我的代码工作。但是,当我使用 stdint.h 将它们指定为 int16_t 时,它将读取第一个值,但不会读取最后一个值。为什么是这样?
这里的代码工作得很好......
#include <stdio.h>
#include <stdint.h>
int main(void)
{
char str[10];
int M, N;
fgets(str, 10, stdin);
sscanf(str, "%d%d", &M, &N);
printf("M is: %d\n", M);
printf("N is: %d\n", N);
return 0;
}
在这里它不起作用。
#include <stdio.h>
#include <stdint.h>
int main(void)
{
char str[10];
int16_t M, N;
fgets(str, 10, stdin);
sscanf(str, "%d%d", &M, &N);
printf("M is: %d\n", M);
printf("N is: %d\n", N);
return 0;
}