C program to create a file and write in it



 c program to create a file and write in it

Learn C - C tutorial - c program to create a file and write in it - C examples - C programs

C program to create a file and write in it

  • This is the Program for creating a file and for storing information.
  • We frequently use files for storing information which can be processed by our programs.
  • In order to store information permanently and retrieve it we need to use files and this program demostrate file creation and writing data in that.

Sample Code

#include <stdio.h>
int main()
{
    int num=778;
    FILE *fptr;
    fptr = fopen("program.txt","w");
    if(fptr == NULL)
    {
        printf("Error!");
        return 1;
    }
    printf("Number to save it in a file:778 ");
    fprintf(fptr,"%d",num);
    fclose(fptr);
    return 0;
}

Output

Number to save it in a file 778 


View More Quick Examples


Related Searches to C program to create a file and write in it