/* Program "exercise03-2.c" --- ファイルからの入力 */ #include #include int main(void) { char name[256]; int age; char hometown[256]; char comment[256]; FILE *fp; /* ファイルオープン */ if((fp = fopen("myprofile.dat", "r")) == NULL ) { printf(" *** file open error *** \n"); exit(1); } /* ファイルからデータの入力(読み出し)*/ fscanf(fp,"name=%s\nage=%d\nhometown=%s\ncomment=%s\n", name, &age, hometown, comment); /* 入力されたデータの表示 */ printf("name=%s\nage=%d\nhometown=%s\ncomment=%s\n", name, age, hometown, comment); /* ファイルクローズ */ fclose( fp ); return 0; }