Hello guys! I really need help. There is such a task:

Create a file consisting of student information structures. The structure contains the following fields: surname, number of ratings, array of ratings (not more than five). Adjust the contents of the file according to the results of unsatisfactory ratings. In this case, the program should issue information on all unsatisfactory ratings and request a new assessment. Provide a view of the contents of the file.

Explain to a newbie how to write an array to a file? And how to adjust the contents of the file according to the results of unsatisfactory grades?

#define N 20 void add_struct_func() {}; typedef struct { char fam; int markscount; int marks [5]; } Students; int main(int argc, const char * argv[]) { @autoreleasepool { NSFileHandle *file; NSMutableData *data; int k = 0, aN, i = 0; //кол-во заполненных ячеек массива Students main_struct[N]; //массив со структурами int neud_mass[N]; BOOL O = 0; printf("Введите количетсво студентов\n"); scanf("%i",&aN); for (i = 0; i < aN; i++) { NSLog(@"Фамилия: "); scanf("%s", &main_struct[i].fam); NSLog(@"Количество оценок: "); scanf("%i", &main_struct[i].markscount); NSLog(@"Оценки: "); for (int j = 0; j < main_struct[i].markscount; j++) { scanf("%i", &main_struct[i].marks[j]); if (main_struct[i].marks[j] < 3) O = 1;//проверка оценки } if (O == 1) { neud_mass[k] = i; k++; } O = 0; } data = [NSMutableData dataWithBytes:&main_struct[N] length:strlen(&main_struct[N])]; file = [NSFileHandle fileHandleForWritingAtPath: @"/Users/Mix-roman/Desktop/ЛАБЫ/ThirdLabObjetive/test2.rtf"]; if (file == nil) NSLog(@"Failed to open file"); [file seekToEndOfFile]; [file writeData: data]; [file closeFile]; } return 0; } 
  • Look in the direction of the NSJSONSerializer for writing and reading (if you can read the entire file into memory). - Andrew Romanov
  • Is it better to just use the C functions fopen, fwrite, fclose? - Maxim Bogdanov

0