A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.cplusplus.com/reference/cstdio/fputs/ below:

function

<cstdio>

fputs
int fputs ( const char * str, FILE * stream );

Write string to stream

Writes the C 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 terminating null-character is not copied to the stream.

Notice that fputs not only differs from puts in that the destination stream can be specified, but also fputs does not write additional characters, while puts appends a newline character at the end automatically.



Parameters
str
C string with the content to be written to stream.
stream
Pointer to a FILE object that identifies an output stream.

Return Value On success, a non-negative value is returned.
On error, the function returns EOF and sets the error indicator (ferror).

Example
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
/* fputs example */
#include <stdio.h>

int main ()
{
   FILE * pFile;
   char sentence [256];

   printf ("Enter sentence to append: ");
   fgets (sentence,256,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 data to stream (function)
fwrite
Write block of data to stream (function)

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4