I've noted a few things in blue.
STUDENT NUMBER \t NAME \t BIRTHDATE \t COURSE
i.e...
Actually, just one space between data would be fine:
e.g.: 2154 Joe Student 12/11/1982 Mathematics
how can i transfer these info accordingly to an array of struct like this?...
Code:
typedef struct student_profile{
long long int stud_num;
char name[50];
char bday[50];
char course[50];
} STUDENT;
....
STUDENT array[20];
i have something like...
Code:
void read_from_file(FILE *file, STUDENT array[20])
{
int i;
if((file = fopen("Students.txt", "rt" == NULL) {
printf("\n File \"Students.txt\" didn't open - exiting program\n");
exit(1);
}
/*if you're reading in a data file, it's important to read it *all*, so a fixed number
for loop is not what I'd recommend. Use a do while loop instead.
*/
MaxStudents = 0;
while((fscanf(file, "%lld %s %s %s", &array[i].stud_num, array[i].name, array[i].bday, array[i].course) != EOF) {
if(array[i].stud_num > 0)
MaxStudents++;
}
}
I added the 't' to the 'r' file mode, because not all systems are set to open files by default, in text mode, which is what you want, here. Mine for instance, opens files in default r or w mode, as binary.
There is a good way to handle this using fread and fwrite, but carry on just as you are doing, Huskar. You need to learn *both* text and binary reads and writes, and you're already well on your way with text reading and writing, with this program.