Q:

Write a C Program to write data into a file using fprintf() function

0

Write a C Program to write data into a file using fprintf() function. Here’s simple Program to write data into a file using fprintf() function in C Programming Language.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Below is the source code for C Program to write data into a file using fprintf() function which is successfully compiled and run on Windows System to produce desired output as shown below :

 
 


SOURCE CODE : :

/*  C Program to write data into a file using fprintf() function  */

#include <stdio.h>
int main()
{
        FILE * fp;
        char file_name[50];

        printf("Enter the file name :: ");
        scanf("%s",file_name);
        fp = fopen (file_name, "w");

        fprintf(fp, "%s %s %s", "Welcome", "to", "CodezClub");
        printf("\nSuccessfully written to the file %s \n",file_name);

        fclose(fp);
        return 0;
}

OUTPUT : :


/*  C Program to write data into a file using fprintf() function  */

Enter the file name :: C:\\Users\\acer\\Documents\\file4.txt

Successfully written to the file C:\\Users\\acer\\Documents\\file4.txt

Process returned 0

Above is the source code for C Program to write a data into a file using fprintf() function which is successfully compiled and run on Windows System.The Output of the program is shown above .

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Write a C Program to copy one file to another with... >>