#include <stdio.h> #include <string.h> #include <stdlib.h> char line[100]; int studentid; char name[30]; float gpa; int main() { FILE *fp; fp = fopen("Data.csv", "r"); if (fp == NULL) { printf("not opening"); exit(0); } char *sp; while (fgets(line, 100, fp) != NULL) { sp = strtok(line, ","); studentid = atoi(sp); sp = strtok(NULL, ","); strcpy(name, sp); sp = strtok(NULL, ","); gpa = atof(sp); printf("\n%d %s", studentid, name); } fclose(fp); return 0; }
1 Brian 2 Clem 3 Abhi
Data.csv
100,Foo,2.5 101,Boo,2.51 102,Goo,0.97
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)