演習 13-4

#include <stdio.h>

int main(){

    FILE *fp;

    int select;
    char name[100];
    double height, weight;

    if(((fp = fopen("hw.dat", "w")) == NULL)){
        printf("can't open file\n");
        return -1;
    }

    while(true){

        printf("名前 身長 体重 : ");
        scanf("%s %lf %lf", name, &height, &weight);

        fprintf(fp, "%s %.lf %.1lf\n", name, height, weight);

        printf("入力を続けますか yes:1/no:0\n");    scanf("%d", &select);
        if(select == 0) break;
    }

    printf("ファイルに書き込みました\n");

    return 0;
}

0 件のコメント:

コメントを投稿