For instance: if the input file "input.txt" is
Joanne,F,500421
Bob,M,48392
Ashley,F,1030381
I am trying to open the file, and read the name part up to comma and store that into a char array, then skip over the comma, the M or F and the next comma, then store the number into a int. I need to do this for every line up to the 100th line. Here is what I have so far, and I know it's wrong, obviously, because it doesn't work.
void processFile(char theFile[11]) {
FILE *inputFile = fopen(&theFile[11], "r");
int line = 1;
char tempName[MAXNAMELEN];
fscanf(inputFile, "%s%[^,]\n", tempName);
printf("%s", tempName);
line++;
fclose(inputFile);
}
int main(void) {
char names[MAXNAMES][MAXNAMELEN];
int ranks[MAXNAMES][YEARS];
int totalNames = 0;
//Init ranks array to all -1 values
memset(ranks, -1, sizeof(ranks[0][0]) * MAXNAMES * YEARS);
//Process all files
processFile("yob1930.txt");
}
So I want the name "Joanne" to be stored in a char[] and the number 500421 into an int. Then move to next line and repeat for the first 100 lines.