Advertisement
Guest User

Untitled

a guest
May 22nd, 2018
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. #include "header.h"
  2.  
  3. void read_peoples_file(PeopleList list){
  4.  
  5. char line[SIZENOME];
  6. char name[SIZENOME];
  7. char email[SIZENOME];
  8. char id[SIZENOME];
  9.  
  10. People pessoa;
  11.  
  12. FILE *fp;
  13.  
  14. fp = fopen("/Users/iroseiro/Desktop/proj_ppp/people.txt", "r");
  15.  
  16. if(fp == NULL){
  17. printf("Erro de leitura ao abrir ficheiro...\n");
  18. return;
  19. }
  20.  
  21. while(fgets(line, SIZENOME, fp) != NULL){
  22. strcpy(name, strtok(line, ";"));
  23. strcpy(email, strtok(line, ";"));
  24. strcpy(id, strtok(line, ";"));
  25.  
  26. strcpy(pessoa.name,name);
  27. strcpy(pessoa.email,email);
  28. pessoa.id = atoi(id);
  29. insert_people(list,pessoa);
  30. }
  31.  
  32.  
  33. fclose(fp);
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement