C Programming Language

fputs()

Declaration: char * fputs(const char *str , FILE *stream);

                   The fputs() function writes the content of the string pointed to by str to the specified stream. The null terminator is not written. The fputs() function returns non negative on success and EOF on failure.

For example, the following program uses fputs() to write a string into a file.

#include<stdio.h>
#include<stdlib.h>
int main()
         {
         FILE *fptr;
         char text[100];
         int i=0;
         clrscr();
         printf(“Enter a text:\n”);
         gets(text);
         if((fptr = fopen(“TEST”,”w”))==NULL)
                      {
                      printf(“Cannot open file\n”);
                      exit(1);
                      }
         fputs(text,fptr);
         if(fclose(fptr))
                        pritf(“File close error\n”);
          getch();
          return 0;
          }

fgetc() Home fgets()

c program stats