LoginSignup
1
0

More than 1 year has passed since last update.

入力バッファの読み捨て

Posted at
main.c
#include <stdio.h>

int main(void)
{
    char buf1[5] = {0}, buf2[5] = {0};
    printf("Input1: ");
    fgets(buf1, sizeof(buf1), stdin);
    // 読み捨て
    while (getchar() != '\n')
        ;
    printf("Input2: ");
    fgets(buf2, sizeof(buf2), stdin);
    // 読み捨て
    while (getchar() != '\n')
        ;
    puts(buf1);
    puts(buf2);
    return 0;
}

結果

キャプチャ.PNG

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0