JOIN us on
WhatsApp Group Join Now
Telegram Join Join Now

हिंदी माध्यम नोट्स

Categories: C Language in hindi

File Management In C : Error Handling और Random Use in hindi एरर हैंडलिंग व रैंडम यूज़ हिंदी में

एरर हैंडलिंग व रैंडम यूज़ हिंदी में File Management In C : Error Handling और Random Use in hindi :-
किसी input/output operation error सकती है |error आने की condition होती है :-
1.जब किसी file मे ,सभी data को read करने के बाद भी read command को perform करना |
2.जब device overflow हो जाये |
3.उस file को use करना जिसे open नहीं किया हुआ |
4.जब किसी file मे उस operation को perform करना जिसके लिए file को choose नहीं किया गया है |
5.किसी file को गलत नाम से open करना |
6.write protected file मे write करना |
जब प्रोग्रामर इन error check किये बिना प्रोग्राम को run किया जाता है प्रोग्राम abnormal behave
करेगे | और error code से प्रोगेम मे unwanted टर्मिनेशन हो जाता है | file handling मे, दो status inquiry library function है जिससे की file मे error handling easily हो सकता है |
1.feof ()
इस
function का use file की end of file condition को check करने के लिए किया जाता है
| ये function file का file pointer को argument की तरह pass होता है |ये function
किसी nonzero integer value को return करता है अगर file के सभी data को read हो
चुके हो|अगर कोई भी data remaining हो तब ये zero return करेगा |
उदहारण
के लिए, अगर ‘f’ किसी file का file pointer है | तब file के data को read करने के
लिए :
if(feof(f))
{
printf(“end
of file error occur”);
}
2.ferror()
ये
function का use किफी file के status को read करने के लिए किया जाता है |इस function
मे , file pointer को argument की तरह करता है |ये function नॉन zero integer को
return करता है अगर कोई error डिटेक्ट होता है |अगर कोई error डिटेक्ट नहीं होती
तो zero return होगा |
उदाहरण
के लिए :
if(ferror!=0)
{
printf(“error
occur”);
}
जब किसी
file को open किया जाता है तब file pointer return होता है |अगर किसी कारन से file
open नहीं होती तब null pointer return होता है |अतः error finding statement :
if(f==NULL)
{
printf(“file
can not open ”);
}
उदहारण
के लिए :
#include<stdio.h>
#include<conio.h>
void main()
{
char *name[10];
FILE *f,*f1;
int i,num,number[10];
f=fopen(“Input”,”w”);
printf(“Enter 10 values”);
for(i=0;i<10;i++)
{
scanf(“%d”,&number[i]);
putw(a[i],f);
}
fclose(f);
print(“Enter file name”);
open file :
scanf(“%s”,&name);
if(f1=fopen(name,”r”)==NULL)
{
printf(“File can not open.”);
printf(“Enetr Other valid file name”);
goto open file ;
}
else
for(i=0;i<10;i++)
{
int num=getw(f1);
if(feof(f1))
{
printf(“\nReading is completed”);
}
else
{
printf(“%d”,num);
}
}
fclose(f1);
}
इस उदहारण मे ,
दो file pointer *f,*f1 है |
सबसे पहले यूजर से 10 values को input किया जाता है उसे array number[10] मे read करा देते है |
फिर इस array elements को file मे write करा देते है |
फिर goto statement का statement block बनाया जाता है जिसमे file pointer की value को check किया जाता है |अगर file pointer की value null होने पर file can not exit का message आ जाता है |और यूजर से फिर से file number input की जाती है |
अगर file pointer की value null नहीं होती तब file मे से data को read करके ,use console screen पर print करा दिया जाता है |
आउटपुट होगा :
Enter 10 values 12 23 34 45 56 45 66 76 12 34
Enter file name Input
12 23 34 45 56 45 66 76 12 34
Reading is completed
Random Access of File
हमने देखा की fprintf() और fscanf() क उपयोग, किसी file के सभी data को read और write करने के लिए किया जाता है |जब किसी file के छोटे भाग को access करने के लिए ftell,fseek और rewind function को इस्तेमाल कर सकते है |
ftell()
ftell() function मे , इस function के argument मे file pointer pass होता है |इस function से एक value return होती जिसका type long होता है |इस function से return value ,उस file की  current position को सेव करता है | इसका  syntax है :-
position variable name = ftell(pointer_name);
यहा पर :
position variable name: ये उस variable का नाम है जिसमे file की current position सेव होती है |
rewind()
इस function का उपयोग ,file की position को file के start मे set हो जाती है |उदहारण के लिए
rewind(file pointer);
n=ftell(file pointer);
इस statement से 0 से n assign होता है |इस function का use किसी file को बार बार read कर सकते है |लेकिन इस operation के लिए , किसी file को open और close को नहीं कर सकते है |
fseek()
इस function का use , किसी file position को desired location पर set कर सकते है |इसका syntax है :-
fseek(file pointer name,move,position);
यहाँ पर :
move की value का type long होती है जो ये declare करता है की movement किस direction मे होगा :
अगर value positive होती है तब movement फॉरवर्ड होगा |
अगर value negative होती है तब movement backward होगा |
position file position को declare करता है |

 

अगर position =0 होगी तब position file की starting होगी |
अगर position =1 होगी तब position file की middle होगी|
अगर position=2 होगी तबposition file की ending होगी |
Sbistudy

Recent Posts

सती रासो किसकी रचना है , sati raso ke rachnakar kaun hai in hindi , सती रासो के लेखक कौन है

सती रासो के लेखक कौन है सती रासो किसकी रचना है , sati raso ke…

1 day ago

मारवाड़ रा परगना री विगत किसकी रचना है , marwar ra pargana ri vigat ke lekhak kaun the

marwar ra pargana ri vigat ke lekhak kaun the मारवाड़ रा परगना री विगत किसकी…

1 day ago

राजस्थान के इतिहास के पुरातात्विक स्रोतों की विवेचना कीजिए sources of rajasthan history in hindi

sources of rajasthan history in hindi राजस्थान के इतिहास के पुरातात्विक स्रोतों की विवेचना कीजिए…

3 days ago

गुर्जरात्रा प्रदेश राजस्थान कौनसा है , किसे कहते है ? gurjaratra pradesh in rajasthan in hindi

gurjaratra pradesh in rajasthan in hindi गुर्जरात्रा प्रदेश राजस्थान कौनसा है , किसे कहते है…

3 days ago

Weston Standard Cell in hindi वेस्टन मानक सेल क्या है इससे सेल विभव (वि.वा.बल) का मापन

वेस्टन मानक सेल क्या है इससे सेल विभव (वि.वा.बल) का मापन Weston Standard Cell in…

3 months ago

polity notes pdf in hindi for upsc prelims and mains exam , SSC , RAS political science hindi medium handwritten

get all types and chapters polity notes pdf in hindi for upsc , SSC ,…

3 months ago
All Rights ReservedView Non-AMP Version
X

Headline

You can control the ways in which we improve and personalize your experience. Please choose whether you wish to allow the following:

Privacy Settings
JOIN us on
WhatsApp Group Join Now
Telegram Join Join Now