0
1.7kviews
Explain need of file data and various modes of files also write program to create and edit copy of file.
1 Answer
0
16views

When a program is terminated, the entire data is lost. Storing in a file will preserve your data even if the program terminates.

If you have to enter a large number of data, it will take a lot of time to enter them all. However, if you have a file containing all the data, you can easily access the contents of the file using few commands in C. You can easily move your data from one computer to another without any changes.

Types of Files

When dealing with files, there are two types of files you should know about:

Text files

Binary files

#include <stdio.h>
int main()
{
    int num;
    FILE *fptr;
    fptr = fopen("C:\\program.txt","w");

    if(fptr == NULL)
    {
        printf("Error!");   
        exit(1);             
    }

    printf("Enter num: ");
    scanf("%d",&num);

    fprintf(fptr,"%d",num);
    fclose(fptr);

    return 0;
}
Please log in to add an answer.