Syntax
#include <stdio.h> int fputs(const char *string, FILE *stream);Description
fputs copies string to the output stream at the current position. It does not copy the null character (\0) at the end of the string.
fputs returns EOF if an error occurs; otherwise, it returns a non-negative value.
This 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 */ perror("fputs failed"); } else perror("Error opening myfile.dat"); return 0; /**************************************************************************** The output should be: Total number of characters written to file = 26 ****************************************************************************/ }Related Information