ファイルを開いて、ファイル・ポインタを作成します。
#include <stdio.h>
FILE *fopen(const char *, const char *);
第1引数 : ファイル名 第2引数 : オープン・モード("r":読込専用、"w":書込専用、"r+","w+":読込書込、"a":[追記モード]書込専用、"a+":[追記モード]読込書込) 戻り値 : NULL以外:ファイル・ポインタ、NULL:失敗
#include <stdio.h> int main () { FILE *fp; char cText[256]; /* ファイル・オープン */ fp = fopen ("open.txt", "r"); if (fp != NULL) { /* ファイル読み出し */ fscanf (fp, "%s", cText); /* 表示 */ printf ("%s\n", cText); /* ファイル・クローズ */ fclose (fp); } return (0); }
abcdefghijklmnopqrstuvwxyz 1234567890
$ ./open abcdefghijklmnopqrstuvwxyz