fputs()

Writes a character array to a stream.

  #include <stdio.h>
  
  int fputs(const char *s, FILE *stream);    
Parameter

s

A pointer to the character string to output.

stream

A pointer to a file stream.

Remarks

The fputs() function writes the array pointed to by s to stream and advances the file position indicator. The function writes all characters in s up to, but not including, the terminating null character. Unlike puts(), fputs() does not terminate the output of s with a newline ( '\n').

If the file is opened in update mode (+) the file cannot be written to and then read from unless the write operation and read operation are separated by an operation that flushes the stream's buffer. This can be done with the fflush() function or one of the file positioning operations ( fseek(), fsetpos(), or rewind()).

This facility may not be available on configurations of the EWL that run on platforms without file systems.

fputs() returns a zero if successful, and returns a nonzero value when it fails.

Listing: Example of fputs() usage

#include <stdio.h>

#include <stdlib.h>

int main(void)

{

FILE *f;

// create a new file for output

if (( f = fopen("foofoo", "w")) == NULL) {

printf("Can't create file.\n");

exit(1);

}

// output character strings to the file

fputs("undo\n", f);

fputs("copy\n", f);

fputs("cut\n", f);

fputs("rickshaw\n", f);

// close the file

fclose(f);

return 0;

}

Output to file foofoo:

undo

copy

cut

rickshaw