read-csv.c (795B)
1 // this is wrong; please do this by counting the characters then allocating. 2 #include <stdio.h> 3 #include "count-columns.h" 4 #include "dynamic-array.h" 5 #include <stdlib.h> 6 7 int main(int argc, char ** argv){ 8 9 char* filename = argv[1]; 10 int columns = countColumns(filename); 11 printf("columns: %d\n", columns); 12 13 int size = 0; 14 char data [size]; 15 FILE* fp = fopen(filename, "r"); 16 DynamicArray* first = makeArr(data,size); 17 DynamicArray* second = makeArr(data,size); 18 19 char c; 20 while ((c = getc(fp)) != ','){ 21 arrAppend(first, c); 22 } 23 24 while ((c = getc(fp)) != '\n'){ 25 arrAppend(second, c); 26 } 27 28 printArr(first); 29 printf("\n"); 30 printArr(second); 31 printf("\n"); 32 33 // todo: cleanup allocations 34 35 fclose(fp); 36 37 return 0; 38 }