> for (x = 0; x < MAX_CLASS; x++); The problem is there.. see that semicolon at the end of the line?
Also, there's no reason to sprintf to a buffer then fprintf the buffer to the file... and in fact there are some reasons not to. You should just fprintf directly to the file. --Palrich.

