fputs Function in C Programming

fputs Function

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

Ready to get started?

Ready to embark on your journey into the world of C programming? Our comprehensive course provides the perfect starting point for learners of all levels. With engaging lessons, hands-on exercises, and expert guidance, you'll gain the skills and confidence needed to excel in this fundamental programming language. Let's dive in and unlock the endless possibilities of C programming together!