#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main()
{
int age, i = 1;
char name[64], addr[512], res[1024];
FILE *fp;
if ((fp=fopen("c://t.txt", "w+")) == 0) {
printf("无法创建文件../n");
exit(1);
}
printf("输入第%d个同学姓名(如果为exit,将退出!): ", i);
scanf("%s", name);
while (strcmp(name, "exit") != 0) {
printf("年龄:");
scanf("%d", &age);
printf("住址:");
scanf("%s", addr);
sprintf(res, "name: %s, age: %d, addr: %s/n", name, age, addr);
fputs(res, fp);
printf("输入第%d个同学姓名(如果为exit,将退出!): ", ++i);
scanf("%s", name);
}
fclose(fp);
return 0;
}
file
最新推荐文章于 2024-03-27 22:44:56 发布