Created
February 23, 2026 07:02
-
-
Save bg1bgst333/13d926d25252943fb8b8e60654a3bd39 to your computer and use it in GitHub Desktop.
scanf#return_value#EOF
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* ヘッダファイルのインクルード */ | |
| #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