| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 
 | #include <stdio.h>
#include <stdlib.h>
 
typedef struct {
   int id;
   char name[30];
   int rooms;
} Hall_info;
 
main (){
 
FILE *fp;
char line[256];
int nh, f=0,j;
 
Hall_info *h;
h = (Hall_info*) malloc(sizeof(Hall_info));
 
if (h == NULL) {
      fprintf(stderr, "out of memory\n");
      exit(1);
}
 
 fp = fopen("residencehalls.txt","r");
   while( fgets(line, 256, fp) ){
      if (line[0] != '#'){
         sscanf(line, "%s %i %i", h[f].name, &h[f].id, &h[f].rooms, );
         nh++;
       } f++;
      } fclose(fp); | 
Partager