鱼C论坛

 找回密码
 立即注册
查看: 1499|回复: 2

文件处理问题

[复制链接]
发表于 2015-10-8 18:14:29 | 显示全部楼层
我输入的是四组啊,没有问题吧
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #define SIZE 4

  4. struct student {
  5.   char name[10];
  6.   int phone;
  7.   char addr[15];
  8. } stu[SIZE];

  9. void save()
  10. {
  11.   FILE *fp;
  12.   int i;

  13.   if(!(fp = fopen("student.txt","wb"))) {
  14.     printf("Cannot find the file!\n");
  15.     return;
  16.   }

  17.   for(i=0; i<SIZE; i++) {

  18.     if( fwrite(&stu[i],sizeof(struct student),1,fp) != 1) {
  19.       printf("File write error!\n");
  20.       fclose(fp);
  21.     }

  22.   }

  23. }

  24. void main()
  25. {
  26.   int i;

  27.   printf("Please input the student's name phone and address: \n");

  28.   for(i=0; i<SIZE; i++) {
  29.     scanf("%s %d %s",&stu[i].name,&stu[i].phone,&stu[i].addr);
  30.   }

  31.   save();
  32.   system("pause");
  33. }
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-11-4 08:48

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表