gtpc2m37 | C/C++ Language Support User's Guide |
This function writes a string to a stream.
Format
#include <stdio.h> int fputs(const char *string, FILE *stream);
This function writes the string pointed to by string to the output stream pointed to by stream. It does not write the terminating \0 at the end of the string.
The fputs function has the same restriction as any write operation for a read immediately following a write or a write immediately following a read. Between a write and a subsequent read, there must be an intervening flush or reposition. Between a read and a subsequent write, there must be an intervening reposition unless an end-of-file (EOF) has been reached.
Normal Return
If successful, the fputs function returns the number of bytes written.
Error Return
If an error occurs, the fputs function returns EOF.
Programming Considerations
The TPF system does not support creating, updating, or deleting files in 1052 or UTIL state. Special files may or may not be writable in 1052 or UTIL state depending on the device driver implementation.
Examples
The following example writes a string to a stream.
#include <stdio.h> #define NUM_ALPHA 26 int main(void) { FILE * stream; int num; /* Do not forget that the '/0' char occupies one character */ static char buffer[NUM_ALPHA + 1] = "abcdefghijklmnopqrstuvwxyz"; if ((stream = fopen("myfile.dat", "w")) != NULL ) { /* Put buffer into file */ if ( (num = fputs( buffer, stream )) != EOF ) { /* Note that fputs() does not copy the /0 character */ printf( "Total number of characters written to file = %i\n", num ); fclose( stream ); } else /* fputs failed */ printf( "fputs failed" ); } else printf( "Error opening myfile.dat" ); }
Related Information
See Appendix E, Programming Support for the TPF File System for more information about TPF File System C Functions.