This apparently has nothing to do with Qt. Are you certain that this is a C++ course? Your program is a C program, and uses the C standard library exclusively; I cannot imagine that a C++ teacher would approve that. On top of that, your code is riddled with buffer overflow vulnerabilities (just think of what scanf "%s" and gets do).

Perhaps you should start over, C++-style, and use C++ iostreams. You will see that they are much easier to deal with than C stdio primitives, in particular when parsing strings. Consider that
Qt Code:
  1. std::string s;
  2. std::cin >> s;
To copy to clipboard, switch view to plain text mode 
takes care of (re)allocating memory for the string as needed.

Now, about your question. In order to compute the arithmetic average for each subject you have to inspect every mark in the database. One solution would be for your program to always keep the database loaded in memory: the file would be loaded and parsed on startup, then the program would exclusively update and inspect this database in memory, and you would only write the database back to a file upon exiting the program. Another solution consists in reopening and reparsing the file on each operation.