Skip to content

Instantly share code, notes, and snippets.

@bg1bgst333
Created February 25, 2026 01:24
Show Gist options
  • Select an option

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

Select an option

Save bg1bgst333/f225cd9586128faf108e83c9825d8f28 to your computer and use it in GitHub Desktop.
errno#ENOENT
/* ヘッダファイルのインクルード */
#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