append to text file
How to append string to newline instead of last line?
#include <stdio.h>#include <stdlib.h>
if ( (fpstream = fopen("sales.txt","a") ) == NULL)
printf("Cannot open sales.txt file.");
Huh? Just output the newline with your data.
Note: the variable named ch invokes a single character rather than a string. Using it with the meaning of string may become troublesome in the future when you review your code (and don't remember most if it)
Make sure you always close every file stream you open. If you dont, the OS will do it for you, but it is good practice to close it
bluechip: there is an fclose call in the code posted.
It's not the OS that does it, but the C library's exit code.
Originally Posted by bluechip