Code:
// - a function that will read in 1 input file
void inputCSV(int year) {
char file_name_start[] = "yob";
char file_name_end[] = ".txt";
char buffer_file_name[20];
char buffer_input_name[MAX_NAME_LENGTH];
sprintf ( buffer_file_name, "%s%d%s",
file_name_start, year, file_name_end);
printf ("\n%s", buffer_file_name);
FILE *csv_file = fopen(buffer_file_name, "r");
printf ("\n%s", buffer_input_name);
fgets ( buffer_input_name, sizeof(buffer_input_name-1), csv_file);
printf ("\n%s", buffer_input_name);
fclose(csv_file);
}
//- a function that will read all 10 input files
void inputFiles(int *ptr_year){
do {
inputCSV(*ptr_year);
(*ptr_year)+=10;
} while ( *ptr_year <= 2010);
}
int input starts at 1910.
MAX_NAME_LENGTH = 35 characters
I am trying to essentially increment the file and save the first 35 characters to a temp string, I understand it will only actually hold 35-1 items due to the terminator.
I am required to pass this string to another function to process the data and pull out the first csv item. I must do so in this manner due to assignment requirements.
currently the program runs and does not print anything unless I comment out the fgets.
if someone would be so kind as to point out what I'm doing wrong that would be awesome.
also, I am passing the int pointer to keep track of the current year being process. file name, file csv format is defined as static and will not change from file to file, except for individual names and numbers.