I'm reading the following file:
Osgood,Marcus 298542123 CHM FR [email protected]
Cronk,Melissa 873489021 BIO SR [email protected]
Pry,Seth 349908431 MTH SO [email protected]
Langlais,Susan 783323545 ME SR [email protected]
Davis,Nicole 987543345 PHY FR [email protected]
It's supposed to split it up into name, ID number, major, year, and email. The file reads it without any errors, and assigns name to the first part of the structure. However, ID gets assigned the ID, major, year, and email. Then Major gets assigned major, year, and email. Year gets assigned year and email, while email just gets assigned email. I don't know if it has something to do with the loop. For example, this is what I get what I print just the name and the ID.
Cronk,Melissa [email protected]
Pry,Seth [email protected]
Langlais,Susan 783323545ME
Davis,Nicole 987543345 [email protected]
-------------------------------------
Anyway. This is my function code for reading the array. I have it printing the ID number just to see if I can catch the errors earlier:
Code:
#include <stdio.h>
#include <string.h>
#include "functions.h"
void read_data(char filename[], studentinfo_t s[], int *size)
{
FILE *infilep;
int countstudents = 0;
infilep = fopen("student_data", "r");
while (fscanf(infilep, "%s %s %s %s %s", s[countstudents].name, s[countstudents].idnum, s[countstudents].major, s[countstudents].year, s[countstudents].email) != EOF)
{
countstudents++;
}
*size = countstudents;
printf("\n%s\n", s[countstudents].idnum);
fclose(infilep);
}
I do not know what I am doing here, the name is reading correctly, but not anything else!
Help would be greatly appreciated!