You probably want artist
and category
to be array of char too.
struct M{
char album[50];
char artist[50];
char category[50];
float price;
int stock;
};
struct M s[10];
then you can use fwrite this way
fwrite(s, sizeof(s), 1, file);
or equivalently
fwrite(s, sizeof(M), 10, file);
You can read in the same manner:
fread(s, sizeof(s), 1, file);
or equivalently
fread(s, sizeof(M), 10, file);
but you will need to open the file before
FILE * file = fopen("thisFile", "bw"); // binary write mode
or
FILE * file = fopen("thisFile", "br"); // binary read mode
Close the file when you're done.
fclose(file);
And check that file is not == NULL after fopen.
However, you will soon want to read/write a file with a size unknown at compile time.
So you will want dynamic memory allocation based on the file size.
But that's for another question ;)
All the info you need can be found there: http://www.cplusplus.com/reference/cstdio/fopen/