Skip to content

Instantly share code, notes, and snippets.

@bg1bgst333
Created February 23, 2026 07:02
Show Gist options
  • Select an option

  • Save bg1bgst333/13d926d25252943fb8b8e60654a3bd39 to your computer and use it in GitHub Desktop.

Select an option

Save bg1bgst333/13d926d25252943fb8b8e60654a3bd39 to your computer and use it in GitHub Desktop.
scanf#return_value#EOF
/* ヘッダファイルのインクルード */
#include <stdio.h> /* 標準入出力 */
/* main関数の定義 */
int main(void){
/* 変数の宣言 */
int x;
int ret;
/* 入力受付を繰り返す. */
while (1){
printf("x: ");
ret = scanf("%d", &x);
if (ret > 0){
printf("x = %d\n", x);
}
else if (ret == 0){
printf("x read failed!\n");
if (feof(stdin)){
printf("feof\n");
}
if (ferror(stdin)){
printf("ferror\n");
}
return 1;
}
else if (ret == EOF){
printf("x read error!\n");
if (feof(stdin)){
printf("feof\n");
}
if (ferror(stdin)){
printf("ferror\n");
}
return 2;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment