हेलो दोस्तों !
आज की इस पोस्ट में हम C language के 10 important file handling function के बारे में जानेंगे और इन सभी के example program भी देखेंगे। तो दोस्तों अगर आप फाइल हैंडलिंग के इन इम्पोर्टेन्ट फंक्शन्स को अच्छी तरह समझना चाहते है तो इस पोस्ट को अंत तक जरूर पढ़ें।
इस पोस्ट के मुख्य टॉपिक्स निन्म है -
- file handling functions क्या है ?
- 10 important file handling function.
- Functions example program video.
1.file handling functions क्या है :-
2.10 important file handling function :-
- fopen() function
- fclose() function
- fread() function
- fwrite() function
- ftell() function
- fseek() function
- rewind() function
- feof() function
- getc() function
- putc() function
1.fopen() function :-
#include< stdio.h >
FILE *ptr;
void main()
{
char str[30]="Hello! how are you.";
char str2[30];
ptr=fopen("test.txt","w");
fputs(str,ptr);
fclose(ptr);
ptr=fopen("test.txt","r");
fgets(str2,sizeof(str2),ptr);
printf("%s\n",str2);
fclose(ptr);
}
2.fcolse() function :-
#include< stdio.h >
FILE *ptr;
void main()
{
char str[30]="Hello! how are you.";
char str2[30];
ptr=fopen("test.txt","w");
fputs(str,ptr);
fclose(ptr);
ptr=fopen("test.txt","r");
fgets(str2,sizeof(str2),ptr);
printf("%s\n",str2);
fclose(ptr);
}
3.fread() function :-
#include< stdio.h >
FILE *ptr;
void main()
{
char str[20]="Hello! how are you.";
char str2[20];
ptr=fopen("test.txt","w");
fwrite(str,sizeof(str)-1,1,ptr);
fclose(ptr);
ptr=fopen("test.txt","r");
fread(str2,sizeof(str),1,ptr);
printf("%s\n",str2);
fclose(ptr);
}
4.fwrite() function :-
#include< stdio.h >
FILE *ptr;
void main()
{
char str[20]="Hello! how are you.";
char str2[20];
ptr=fopen("test.txt","w");
fwrite(str,sizeof(str)-1,1,ptr);
fclose(ptr);
ptr=fopen("test.txt","r");
fread(str2,sizeof(str),1,ptr);
printf("%s\n",str2);
fclose(ptr);
}
5.ftell() function :-
#include< stdio.h >
FILE *ptr;
void main()
{
int length;
char str[30]="Hello! how are you.";
char str2[30];
ptr=fopen("test.txt","w");
fputs(str,ptr);
fclose(ptr);
ptr=fopen("test.txt","r");
fgets(str2,sizeof(str2),ptr);
printf("%s\n",str2);
length=ftell(ptr);
printf("File lenth=%d\n",length);
rewind(ptr);
length=ftell(ptr);
printf("File lenth=%d\n",length);
fclose(ptr);
}
6.fseek() function :-
#include< stdio.h >
#include< string.h >
FILE *ptr;
void main()
{
int length;
char str[30]="Hello! My name is SANJAY.";
char str2[7]="AKSHAY";
ptr=fopen("test.txt","w");
fputs(str,ptr);
length=strlen(str2);
fseek(ptr,(ftell(ptr)-length)-1,SEEK_SET);
fputs(str2,ptr);
fclose(ptr);
}
7.rewind() function :-
#include< stdio.h >
FILE *ptr;
void main()
{
int length;
char str[30]="Hello! how are you.";
char str2[30];
ptr=fopen("test.txt","w");
fputs(str,ptr);
fclose(ptr);
ptr=fopen("test.txt","r");
fgets(str2,sizeof(str2),ptr);
printf("%s\n",str2);
length=ftell(ptr);
printf("File lenth=%d\n",length);
rewind(ptr);
length=ftell(ptr);
printf("File lenth=%d\n",length);
fclose(ptr);
}
8.feof() function :-
#include< stdio.h >
FILE *ptr;
void main()
{
char str[20]="Hello! how are you.";
ptr=fopen("test.txt","w");
fputs(str,ptr);
fclose(ptr);
ptr=fopen("test.txt","r");
while (!feof(ptr))
{
printf("%c",getc(ptr));
}
fclose(ptr);
}
9.getc() function :-
#include< stdio.h >
FILE *ptr;
void main()
{
char ch='A';
char ch2='B';
ptr=fopen("test.txt","w");
putc(ch,ptr);
putc(ch2,ptr);
fclose(ptr);
ptr=fopen("test.txt","r");
printf("%c",getc(ptr));
printf("%c",getc(ptr));
fclose(ptr);
}
10.putc() function :-
#include< stdio.h >
FILE *ptr;
void main()
{
char ch='A';
char ch2='B';
ptr=fopen("test.txt","w");
putc(ch,ptr);
putc(ch2,ptr);
fclose(ptr);
ptr=fopen("test.txt","r");
printf("%c",getc(ptr));
printf("%c",getc(ptr));
fclose(ptr);
}
3.Functions example program video :-
तो दोस्तों अगर आप ऊपर दिए गए example program की वीडियो देखना चाहते है तो आप हमारी यह वीडियो नीचे लिंक करके you tube पर देख सकते है। हमने इस वीडियो में इन सभी फंक्शन्स के प्रोग्राम बनाकर और रन करके दिखाया है। तो अगर आप इस वीडियो को you tube पर देखना चाहते है तो नीचे लिंक पर क्लिक करके देख सकते है।
इन पोस्ट को भी पढ़े -
- important functions of stdio.h header file.
- important functions of conio.h header file.
- important functions of string.h header file.
- important functions of math.h header file.
Author :- तो दोस्तों अब हमारी यह पोस्ट ख़त्म होती है हम आशा करते है की आपको हमारी यह पोस्ट जरूर पसंद आई होगी और आप C language के 10 important file handling functions को अच्छी तरह समझ गए होंगे। तो दोस्तों आज के लिए बस इतना ही फिर मिलेंगे ऐसी ही किसी और मजेदार पोस्ट में तब तक के लिए अलविदा !
0 Comments
Do not enter any spam comments please.