If you do to warm up, you can decide that you are writing the ArrayStudents structure to the file and expect that this will entail an automatic recording of the data pointed to by the PtrSt field. But it is not. Try to look at the created structure in the debugger (memory dump mode), draw on a piece of paper (with your hands! Pen, pencil ...) the memory allocation when initializing such a structure and adding students to it. It will become clear that 1) students need to be recorded separately and 2) the entire structure of ArrayStudents is not necessary to record.
For example, the entry:
struct ArrayStudents students; /* ... добавили студентов ... */ fwrite( &students.Count, sizeof(students.Count), 1, file ); for( int i = 0; i < students.Count; i++ ) { fwrite( students.PtrSt[i], sizeof(struct Student), 1, file ); }
Reading:
int Count; fread( &Count, sizeof(Count), 1, file ); /* ... создали структуру ArrayStudents на Count студентов ... */ for( int i = 0; i < Count; i++ ) { fread( students.PtrSt[i], sizeof(struct Student), 1, file ); }
fwrite()? See in the description of your library, orman fwrite. How to write withfread()? It's simple: no way,fread()doesn't write anything in principle. - user6550