int fputs ( const char * str, FILE * stream ); |
<cstdio> |
Write string to stream
Writes the string pointed by str to the stream.
The function begins copying from the address specified (str) until it reaches the terminating null character ('\0'). This final null-character is not copied to the stream.
Parameters
- str
- An array containing the null-terminated sequence of characters to be written.
- stream
- Pointer to a FILE object that identifies the stream where the string is to be written.
Return Value
On success, a non-negative value is returned.
On error, the function returns
EOF.
Example
/* fputs example */
#include <stdio.h>
int main ()
{
FILE * pFile;
char sentence [256];
printf ("Enter sentence to append: ");
fgets (sentence,255,stdin);
pFile = fopen ("mylog.txt","a");
fputs (sentence,pFile);
fclose (pFile);
return 0;
}
|
This program allows to append a line to a file called mylog.txt each time it is run.
See also
puts | Write string to stdout (function) |
fgets | Get string from stream (function) |
fputc | Write character to stream (function) |
fprintf | Write formatted output to stream (function) |
fwrite | Write block of data to stream (function) |