File Handling :- before a fle is emplemented in a C program, every data of every variable ws stored on RAM since RAM is temporary memory, every data sucscptble (doubtful) to delete.
To over come this, and make permanent storage of our data reimplement file handling how the data wll stored in a file on hard disk show that it can be accessed any time.
Function of file handling in C :-
S.No. Function Description

1- fopen() creat a file
2- fclose() close a file
3- getc() read a character from file
4- putc() write a character to file
5- getw() read an integer from file
6- putw() write an integer to file
7- fprintf() writes a set of values to file
8- fscanf() reads a set of values from file
fopen():-This function opens a file is opened with a proper mod and the address of that file will be placed to a pointer.
Thetwo important mod of opening a file are-
read mod ("r")
write mod ("w")
Syntax:- fp=fopen("Abc.txt","r");
Here fp is the file pointer, fopeon is the function for opening the file, Abc.txt is the name of the file, r is mod (read mod).
fclose():-fclose function close the file with help of its pointer.
syntax:-fclose(fp);
Here fp is pointer of the file that is to be closed.
getc():-getc is use to read a character from a file.getc is a function of with argument with return type. Its argument is file pointer and its return is the character read from that file.
Syntax:-char ch;
ch=getc(fp);
Here the character read from the file goes in ch and fp is file pointer.
putc():-putc is use to write a character to a file.putc is a function of with argument without return type. It usage two argument the first is the character variable and second is file pointer.
Syntax:-char ch;
ch=putc(ch,fp);
Here ch is character variable and fp is file pointer.
getw():-This function reads an integer values from the file. Its argument is the file pointer and its return is the integer values read from that file.
Syntax:-int ch;
ch=getw(fp);
putw():-This function writes an integer values to the file. It usage two argument the first is the integer variable and second is file pointer.
Syntax:-int ch;
ch=putw(ch,fp);
fprintf():-This function writes a set of different values of different type in to a file.
Syntax:-fprintf(fp"_____",____);
Here fp is file pointer, "_____" is list control string (like-%d%s%f)and ____ is list of values to be written to the file.
fscanf():-This function reads a set of different values of different type from a file.
Syntax:-fscanf(fp"_____",____);
Here fp is file pointer, "_____" is list control string (like-%d%s%f)and ____ is list of values to be reads from the file(preceded by &).
Writting a character to a file:-

#include< stdio.h>
#include< conio.h>
void main()
{
FILE *fp1;
char ch;
clrscr();
fp1=fopen("text1.txt","w");
printf("Enter a character: ");
ch=getchar();
{
putc(ch,fp1);
}
fclose(fp1);
fp1=fopen("text1.txt","r");
while((ch=getc(fp1))!=EOF)
{
printf("%c",ch);
}
fclose(fp1);
getch();
}

This program takes a character from the console screen than writes in to a file finely reads that character from the file and display it on the console.

Writting a text to a file:-

#include< stdio.h>
#include< conio.h>
void main()
{
FILE *fp1;
char ch;
clrscr();
fp1=fopen("text.txt","w");
printf("Enter text");
while((ch=getchar())!=EOF)
{
putc(ch,fp1);
}
fclose(fp1);
fp1=fopen("text.txt","r");
while((ch=getc(fp1))!=EOF)
{
printf("%c",ch);
}
fclose(fp1);
getch();
}

Writting a integer to a file:-

#include< stdio.h>
#include< conio.h>
void main()
{
FILE *fp1;
int ch;
clrscr();
fp1=fopen("text2.txt","w");
printf("Enter a number: ");
scanf("%d",&ch);
{
putw(ch,fp1);
}
fclose(fp1);
fp1=fopen("text2.txt","r");
while((ch=getw(fp1))!=EOF)
{
printf("%d",ch);
}
fclose(fp1);
getch();
}

This program takes an integer values and writes it in to the file Data2.txt. furhter it reads that file and display that integer on to the console.

Write a program that input 20 integer values and writes it in to a file further reads every ood moves it to a file and if the element is even moves it to another file.

#include< stdio.h>
#include< conio.h>
void main()
{
FILE *fp1,*fp2,*fp3;
int n,i;
clrscr();
fp1=fopen("Data.txt","w");
for(i=1;i<=20;i++)
{
printf("enter a value:");
scanf("%d",&n);
putw(n,fp1);
}
fclose(fp1);
fp1=fopen("Data.txt","r");
fp2=fopen("Odd.txt","w");
fp3=fopen("Even.txt","w");
//printf("Element of first file- ");
while((n=getw(fp1))!=EOF)
{
if(n%2==0)
{
putw(n,fp3);
}
else
{
putw(n,fp2);
}
}
fclose(fp1);
fclose(fp2);
fclose(fp3);
fp2=fopen("Odd.txt","r");
fp3=fopen("Even.txt","r");
printf("\nOdd element: ");
while((n=getw(fp2))!=EOF)
{
printf("%d ",n);
}
fclose(fp2);
printf("\nEven element: ");
while((n=getw(fp3))!=EOF)
{
printf("%d ",n);
}
fclose(fp3);
getch();
}