Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- char * srcFile;
- char ** times;
- char ** volumes;
- // Open the file stream
- FILE * file = fopen(fileName, "r");
- if(file == NULL){
- printf("nError. File not found!n");
- }
- // how many lines does the csv file have
- int lines = 0;
- // The current line string
- char * line;
- // The length of the current line
- size_t len = 0;
- // determine the size of the file
- while((getline(&line, &len, file)) != -1){
- lines++;
- }
- // now that we know the size we can allocate the memory for the arrays
- times = malloc((sizeof (char *)) * lines); //array of times
- volumes = malloc((sizeof (char *)) * lines); //array of volumes
- // we've read through the whole file, so close it
- fclose(file);
- // reopen it so that we are at the beginning
- file = fopen("./HeatingSchedule00.csv", "r");
- // read and discard the first line
- getline(&line, &len, file);
- // keep track of the the line we are on
- int currentLine = 0;
- // loop through the file
- while(getline(&line, &len, file) != -1){
- // populate the times and volumes array
- parseCSV(line, times[currentLine], volumes[currentLine]);
- //move on to the next line
- currentLine++;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement