fprintf

suggest change

You can use fprintf on a file just like you might on a console with printf. For example to keep track of game wins, losses and ties you might write

/* Record wins, ties, and losses, in that order. */
void savewlt(FILE *fout, int wins, int losses, int ties)
{
    fprintf(fout, "Wins: %d\nTies: %d\nLosses: %d\n", wins, ties, losses);
}

A side note: some systems, notably Windows, represent a text-file line ending as CR LF (\r\n) rather than a single newline. In C, the '\n' character in a string is still one newline character. When that character is written to a text stream, the library translates it to the host's line ending. A Windows text stream commonly writes \r\n; a Unix text stream writes \n. Binary mode does not perform that translation. The compiler does not rewrite the bytes of the string literal itself.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents