Register Now

Login

Lost Password

Enter your email to reset your password.

BY Author

The fputs() function

This function is used to write a line of characters (string) into the file.

Syntax

int fputs(const char *s, FILE *fp);

Example no 1

#include<stdio.h>
int main()
{
    FILE *fp;
    fp=fopen("D:\\C Programming\\file3.txt","w");
    if(fp==NULL)
    {
        printf("\n Unable to open the FILE");
        return 1;
    }
	
    fputs("Have a Nice Day",fp);
    fclose(fp);
    return 0;
}

Inside file3.txt

C Programming Language fputs Function in File Handling Example 1

Example no 2

#include<stdio.h>
int main()
{
    FILE *fp;
    char str[50] = " Hello! \n Have a Nice Day.";
    fp=fopen("D:\\C Programming\\file4.txt","w");
    if(fp==NULL)
    {
        printf("\n Unable to open the FILE");
        return 1;
    }
    fputs(str,fp);
    fclose(fp);
    return 0;
}

Inside file4.txt

C Programming Language fputs Function in File Handling Example 2
 

Leave a reply