Advertisement
Guest User

Untitled

a guest
Oct 26th, 2016
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. char * srcFile;
  2. char ** times;
  3. char ** volumes;
  4.  
  5. // Open the file stream
  6. FILE * file = fopen(fileName, "r");
  7.  
  8. if(file == NULL){
  9. printf("nError. File not found!n");
  10. }
  11.  
  12. // how many lines does the csv file have
  13. int lines = 0;
  14. // The current line string
  15. char * line;
  16. // The length of the current line
  17. size_t len = 0;
  18.  
  19.  
  20.  
  21. // determine the size of the file
  22. while((getline(&line, &len, file)) != -1){
  23. lines++;
  24. }
  25.  
  26. // now that we know the size we can allocate the memory for the arrays
  27. times = malloc((sizeof (char *)) * lines); //array of times
  28. volumes = malloc((sizeof (char *)) * lines); //array of volumes
  29.  
  30. // we've read through the whole file, so close it
  31. fclose(file);
  32.  
  33. // reopen it so that we are at the beginning
  34. file = fopen("./HeatingSchedule00.csv", "r");
  35.  
  36. // read and discard the first line
  37. getline(&line, &len, file);
  38.  
  39. // keep track of the the line we are on
  40. int currentLine = 0;
  41.  
  42. // loop through the file
  43. while(getline(&line, &len, file) != -1){
  44. // populate the times and volumes array
  45. parseCSV(line, times[currentLine], volumes[currentLine]);
  46. //move on to the next line
  47. currentLine++;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement