Well, it’s possible to make your program compile, but it raises 7 important warnings: just reading them would help you a lot.
Your error description is too concise and you didn’t provide any examples of your data, so it’s hard to guess where the main problem could be. However, in my opinion you could at least improve your program in three ways:
1) You shouldn’t declare your variables in a bunch at the beginning of functions, because it can leads to hard to detect bugs.
For example, in addAlbum(), the variable ‘genreID’ is declared, but later neglected.
Is it possible that it was supposed to contain some data which later had to be written to some file and, skipping it, the ‘fields’ in that file will move in the wrong sequence?
Anyway, if you hadn’t declare ‘artistName’ so far from where you use it, you'd probably noticed you close() ‘outputFile’ inside a loop, so that it closes at the first iteration - it means later you attempt to write to a closed stream.
Please, have a look here:
https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#Rnr-top
2) Do not write to much before testing your code.
Try to compile it often. Do not neglect warnings just because they don’t stop compilation.
You functions are long and, in my opinion, they don’t belong where they are.
I think they should be methods of a class that manages all those information.
If you store your information into local objects, you’ll need to read them again every time you need them.
(Well, it actually could be a design choice, if you loaded in memory only the relevant data)
You could consider splitting long functions into smaller ones, e.g. a function for every writing operation - I mean one for updating artist file, one for updating album file…
3)
Album albums[c.albumCount];
Variable length arrays are not welcome in C++. What about std::vectors?
Also:
- do try to be a bit more consistent in your spacing and indentation;
- do avoid “using namespace std” (only experienced programmers should use it);
- let us test your code against your data files;
- do consider exiting from functions returning error codes in case of failures.
In the next two posts I’m going to provide an example of your code written in a slightly different style (just for comparison) and unified into a single file. It deals with some minor issues, but not with the biggest ones mentioned above.