C examples for stdio.h:fputs
function
<cstdio> stdio.h
Write string to stream
int fputs ( const char * str, FILE * stream );
Parameter | Description |
---|---|
str | C string to be written. |
stream | FILE object. |
On success, a non-negative value is returned.
On error, the function returns EOF and sets the error indicator (ferror).
The following code appends a line to a file called main.cpp.
#include <stdio.h> int main ()//w ww.j ava 2 s .c om { FILE * pFile; char sentence [256]; printf ("Enter sentence to append: "); fgets (sentence,256,stdin); pFile = fopen ("main.cpp","a"); fputs (sentence,pFile); fclose (pFile); return 0; }