SHARE
TWEET

Untitled

a guest Apr 21st, 2017 44 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. fscanf(fp, "%s", record[0].first_name);
  2.    
  3. #include <stdio.h>
  4.  
  5.     struct student
  6.     {
  7.         int id;
  8.         char first_name[20];
  9.         char last_name[20];
  10.         char email[50];
  11.         char gender[6];
  12.         int grade;
  13.     };
  14.  
  15.     int main()
  16.     {
  17.         FILE *fp;
  18.         int count_lines = 0;
  19.         char chr, header_row[44];
  20.         struct student record[10000];
  21.  
  22.         fp = fopen("/Users/tenorjas/Documents/USF courses/EEL 2161 C programming/exampledata.csv","r");
  23.  
  24.         // extract character from file and store in chr
  25.         chr = getc(fp);
  26.  
  27.         while (chr != EOF)
  28.         {
  29.             // Count whenever new line is encountered
  30.             if (chr == 'n')
  31.             {
  32.                 count_lines = count_lines + 1;
  33.             }
  34.  
  35.             // Get next character from file
  36.             chr = getc(fp);
  37.         }
  38.  
  39.         printf("There are %i lines in file exampledata.csvn", count_lines);
  40.  
  41.         fseek(fp, 0, SEEK_SET); // go back to beginning of file
  42.  
  43.         fgets(header_row, 44, fp); // read the header row of the file
  44.         printf("%sn", header_row); // display the header row
  45.  
  46.         fscanf(fp, "%i", &record[0].id);
  47.         printf("%in", record[0].id);
  48.         fscanf(fp, "%s", record[0].first_name);
  49.         printf("%sn", record[0].first_name);
  50.         fclose(fp); // close file
  51.  
  52.         return 0;
  53.     }
RAW Paste Data
Pastebin PRO Summer Special!
Get 40% OFF on Pastebin PRO accounts!
Top