Try replacing
fprintf(fp,"%d ", number);
with
fprintf(fp," %d", number);
and Notepad will display it correctly.
Notepad has a problem with the long length of the line and the final space at the end of it, don't ask me why.
If you open your original 'corrupted' file in Wordpad it is displayed correctly.