明解c语言 13-4
Posted 小虾米2018
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了明解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; }
以上是关于明解c语言 13-4的主要内容,如果未能解决你的问题,请参考以下文章