Created
February 25, 2026 01:24
-
-
Save bg1bgst333/f225cd9586128faf108e83c9825d8f28 to your computer and use it in GitHub Desktop.
errno#ENOENT
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> /* 標準入出力 */ | |
| #include <errno.h> /* errno */ | |
| /* main関数の定義 */ | |
| int main(void){ | |
| /* ポインタの宣言 */ | |
| FILE *fp; | |
| /* ファイルを開く. */ | |
| fp = fopen("test.txt", "r"); | |
| if (fp == NULL){ /* NULLなら失敗. */ | |
| /* errnoがENOENTの場合, "errno == ENOENT"と出力. */ | |
| if (errno == ENOENT){ | |
| printf("errno == ENOENT\n"); | |
| } | |
| /* perrorでエラー内容を出力. */ | |
| perror("fopen"); | |
| return 1; | |
| } | |
| /* ファイルを閉じる. */ | |
| fclose(fp); | |
| /* プログラムの終了 */ | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment