Showing posts with label fput() function in c programming. Show all posts
Showing posts with label fput() function in c programming. Show all posts

Sunday, October 4, 2020

, ,

fput() program in C programming language

 fput() function in c programming is a file string function which is used to print a string to the file.

fput() function use two arguments pointer one of them is used for string and other one for file. 

A null terminated string pointed by str in to a file.A null character is not written into a given and at the time of success it returns the 0 and  EOF or -1.

fput() program in c language : -


#include<stdio.h>
#include<string.h>

int main()
{
    char str[50];
    FILE *fp;
    fp = fopen("yourfile2.txt", "w");

    if(fp == NULL)
    {
        printf("Error for opening file\n");
        exit(1);
    }

    printf("Testing with the help of fputs() function: \n\n");
    printf("To stop reading press Ctrl+Z in windows and Ctrl+D in Linux :");

    while( gets(str) != NULL )
    {
        fputs(str, fp);
    }

    fclose(fp);
    return 0;
}


Output :-

fput() program in C programming language
fput() program in C programming language