Advertisement
AbraaoAllysson

readCSV in C

Apr 14th, 2016
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.50 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int main(void)
  4. {
  5.     FILE *fp = fopen("voos.txt", "r");
  6.     if(!fp) { printf("Erro ao abrir o arquivo.\n"); exit(1); }
  7.     int voo;
  8.     char id[4] = {0}, cia[30] = {0}, cidade[30] = {0}, hora[10] = {0}, obs[15] = {0};
  9.  
  10.     /* G3 2161;Gol;(FLN) Florianopolis;9:05 AM;En Route; */
  11.  
  12.     while(fscanf(fp, "%s %d;%[^';'];%[^';'];%[^';'];%[^';'];\n", id, &voo, cia, cidade, hora, obs) != EOF)) {
  13.         fprintf(stdout, "%s %d;%s;%s;%s;%s;",id, voo, cia, cidade, hora, obs);
  14.     }
  15.  
  16.     fclose(fp);
  17.  
  18.     return 0;
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement