Replace writing using fputs and fputc with one fprintf statement