Advertisement
Guest User

Untitled

a guest
May 10th, 2011
2,017
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.82 KB | None | 0 0
  1. #include <stdio.h>
  2. #define MAX_PEOPLE_SIZE 200
  3.  
  4.  
  5. typedef struct people
  6. {
  7.   char code[10];
  8.   char first_name[50];
  9.   char last_name[50];
  10.   long telephone;
  11. } PEOPLE;
  12.  
  13.  
  14. int main()
  15. {
  16.    FILE* fp = fopen("example.txt", "r");
  17.    int i = 0;
  18.    PEOPLE people[MAX_PEOPLE_SIZE];
  19.    int size;
  20.  
  21.    while (!feof(fp)) {
  22.        read(people, i, fp);
  23.        i++;
  24.    }
  25.    size = i;
  26.  
  27.    for (i = 0; i < size; ++i)
  28.      printf("%s, %s, %s, %ld\n", people[i].code, people[i].first_name,
  29.         people[i].last_name, people[i].telephone);
  30.    
  31.  
  32.    fclose(fp);
  33. }
  34.  
  35. int read(PEOPLE people[], int n_p, FILE* fp){
  36.    char temp;
  37.  
  38.    if(fp==NULL){
  39.        printf("Error\n");
  40.        return -1;
  41.    }
  42.    fscanf(fp,"%s %s %s %ld\n", people[n_p].code, people[n_p].first_name,
  43.       people[n_p].last_name, &people[n_p].telephone);
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement