Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- fscanf(fp, "%s", record[0].first_name);
- #include <stdio.h>
- struct student
- {
- int id;
- char first_name[20];
- char last_name[20];
- char email[50];
- char gender[6];
- int grade;
- };
- int main()
- {
- FILE *fp;
- int count_lines = 0;
- char chr, header_row[44];
- struct student record[10000];
- fp = fopen("/Users/tenorjas/Documents/USF courses/EEL 2161 C programming/exampledata.csv","r");
- // extract character from file and store in chr
- chr = getc(fp);
- while (chr != EOF)
- {
- // Count whenever new line is encountered
- if (chr == 'n')
- {
- count_lines = count_lines + 1;
- }
- // Get next character from file
- chr = getc(fp);
- }
- printf("There are %i lines in file exampledata.csvn", count_lines);
- fseek(fp, 0, SEEK_SET); // go back to beginning of file
- fgets(header_row, 44, fp); // read the header row of the file
- printf("%sn", header_row); // display the header row
- fscanf(fp, "%i", &record[0].id);
- printf("%in", record[0].id);
- fscanf(fp, "%s", record[0].first_name);
- printf("%sn", record[0].first_name);
- fclose(fp); // close file
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement