明解c语言 13-4
作者:互联网
1、
#include <stdio.h> int main(void) { FILE *fp; char name[128]; double height, weight; if((fp = fopen("a.txt", "w")) == NULL) printf("\aFile open failed.\n"); else { int i; for(i = 0; i < 6; i++) { printf("NO%d.name = ", i + 1); scanf("%s", name); printf("NO%d.height = ", i + 1); scanf("%lf", &height); printf("NO%d.weight = ", i + 1); scanf("%lf", &weight); fprintf(fp, "%s %.2f %.2f\n", name, height, weight); } fclose(fp); } return 0; }
2、
#include <stdio.h> int main(void) { FILE *fp; typedef struct{ char name[128]; double height; double weight; }Type1; int i; Type1 x[6]; if((fp = fopen("a.txt", "w")) == NULL) printf("\aFile open failed.\n"); else { for(i = 0; i < 6; i++) { printf("x[%d].name = ", i); scanf("%s", x[i].name); printf("x[%d].height = ", i); scanf("%lf", &x[i].height); printf("x[%d].weight = ", i); scanf("%lf", &x[i].weight); fprintf(fp, "%s %.2f %.2f\n", x[i].name, x[i].height, x[i].weight); } fclose(fp); } return; }
标签:fp,13,语言,weight,scanf,明解,height,printf,name 来源: https://www.cnblogs.com/liujiaxin2018/p/14872995.html