fputs - C stdio.h

C examples for stdio.h:fputs

Type

function

From

<cstdio>
stdio.h

Description

Write string to stream

Prototype

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

Parameters

ParameterDescription
str C string to be written.
stream FILE object.

Return Value

On success, a non-negative value is returned.

On error, the function returns EOF and sets the error indicator (ferror).

Example

The following code appends a line to a file called main.cpp.

Demo Code


#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;
}

Related Tutorials