The work of the program is as follows: it is written into a binary file in blocks of info about students. At each addition operation, the last block read from the file is checked for availability. If there is no space left, then a new one is created. The problem is this: when creating a block inside the function of adding and writing it, there are numerous letters "M" in the file, that is, as if the created block remained uninitialized, although the debugger says the opposite: 
The problem is solved if you create a global variable of the "block" type, but it seems to me that this is not the best way out of this situation. Below is the code of the method of adding a student to the file:
void AddStudent(Student tempStudent) { filePointer = fopen(FILE_NAME, "rb+"); if (fileSize == SIZE * BLOCK_SIZE) { numberOfBlocks++; } int pastePosition = -1; for (int i = 0; i < BLOCK_SIZE; i++) //Находим позицию в блоке для добавления студента { if (buffer.students[i].id == 0) { pastePosition = i; break; } } if (pastePosition != -1) //Если есть место в блоке, вставляем запись { buffer.students[pastePosition].id = tempStudent.id; strcpy(buffer.students[pastePosition].surname, tempStudent.surname); strcpy(buffer.students[pastePosition].name, tempStudent.name); strcpy(buffer.students[pastePosition].patronymic, tempStudent.patronymic); buffer.students[pastePosition].groupNumber = tempStudent.groupNumber; for (int i = pastePosition + 1; i < BLOCK_SIZE; i++)//Заполняем нулями остальные места в блоке { buffer.students[i].id = 0; strcpy(buffer.students[i].surname, ""); strcpy(buffer.students[i].name, ""); strcpy(buffer.students[i].patronymic, ""); buffer.students[i].groupNumber = 0; } fseek(filePointer, SIZE * BLOCK_SIZE * numberOfBlocks , SEEK_SET); cout << ftell(filePointer); system("pause"); fwrite(&buffer, sizeof(DataBlock), 1, filePointer); } else { DataBlock tempBlock; //Иначе создаём новую tempBlock.students[0].id = tempStudent.id; strcpy(tempBlock.students[0].surname, tempStudent.surname); strcpy(tempBlock.students[0].name, tempStudent.name); strcpy(tempBlock.students[0].patronymic, tempStudent.patronymic); tempBlock.students[0].groupNumber = tempStudent.groupNumber; for (int i = 1; i < BLOCK_SIZE; i++) //Заполняем нулями остальные места в блоке { tempBlock.students[i].id = 0; strcpy(tempBlock.students[i].surname, ""); strcpy(tempBlock.students[i].name, ""); strcpy(tempBlock.students[i].patronymic, ""); tempBlock.students[i].groupNumber = 0; } numberOfBlocks++; fseek(filePointer, SIZE * BLOCK_SIZE * numberOfBlocks, SEEK_SET); cout << ftell(filePointer); system("pause"); fwrite(&tempBlock, sizeof(DataBlock), 1, filePointer); } fseek(filePointer, 0, SEEK_END); fileSize = ftell(filePointer); fclose(filePointer); }
cout << ftell(filePointer);- Yaroslavstrcpy(tempBlock.students[i].surname, "");in fact, it simply writes one zero to the very first byte, and does not touch the rest. - KoVadim