/* キーボードから、名前、身長、体重を読み込んで、 それをファイルに書き込むプログラムを作成せよ。 ファイルへ書き込む形式は、List13-2と同様にすること。 */ #include typedef struct { char name[128]; double height; double weight; } nhw; int main(void) { FILE *wfp; nhw people; char fname[256] = "hw2.dat"; if((wfp = fopen(fname, "w")) == NULL) puts("\aファイルをオープンできません。"); else { printf("名前を入力してください:"); scanf("%s", &people.name); printf("身長を入力してください:"); scanf("%lf", &people.height); printf("体重を入力してください:"); scanf("%lf", &people.weight); fprintf(wfp, "%s %.0lf %.1lf", people.name, people.height, people.weight); fclose(wfp); } return 0; }