| 
 | 
 
 
发表于 2015-10-8 18:14:29
|
显示全部楼层
 
 
 
我输入的是四组啊,没有问题吧 
- #include <stdio.h>
 
 - #include <stdlib.h>
 
 - #define SIZE 4
 
  
- struct student {
 
 -   char name[10];
 
 -   int phone;
 
 -   char addr[15];
 
 - } stu[SIZE];
 
  
- void save()
 
 - {
 
 -   FILE *fp;
 
 -   int i;
 
  
-   if(!(fp = fopen("student.txt","wb"))) {
 
 -     printf("Cannot find the file!\n");
 
 -     return;
 
 -   }
 
  
-   for(i=0; i<SIZE; i++) {
 
  
-     if( fwrite(&stu[i],sizeof(struct student),1,fp) != 1) {
 
 -       printf("File write error!\n");
 
 -       fclose(fp);
 
 -     }
 
  
-   }
 
  
- }
 
  
- void main()
 
 - {
 
 -   int i;
 
  
-   printf("Please input the student's name phone and address: \n");
 
  
-   for(i=0; i<SIZE; i++) {
 
 -     scanf("%s %d %s",&stu[i].name,&stu[i].phone,&stu[i].addr);
 
 -   }
 
  
-   save();
 
 -   system("pause");
 
 - }
 
 
  复制代码 |   
 
 
 
 |