ユーザー入力ストリームから変数 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;
}