JOIN us on
WhatsApp Group Join Now
Telegram Join Join Now

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

Class 6

Hindi social science science maths English

Class 7

Hindi social science science maths English

Class 8

Hindi social science science maths English

Class 9

Hindi social science science Maths English

Class 10

Hindi Social science science Maths English

Class 11

Hindi sociology physics physical education maths english economics geography History

chemistry business studies biology accountancy political science

Class 12

Hindi physics physical education maths english economics

chemistry business studies biology accountancy Political science History sociology

Home science Geography

English medium Notes

Class 6

Hindi social science science maths English

Class 7

Hindi social science science maths English

Class 8

Hindi social science science maths English

Class 9

Hindi social science science Maths English

Class 10

Hindi Social science science Maths English

Class 11

Hindi physics physical education maths entrepreneurship english economics

chemistry business studies biology accountancy

Class 12

Hindi physics physical education maths entrepreneurship english economics

chemistry business studies biology accountancy

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

द्वितीय कोटि के अवकल समीकरण तथा विशिष्ट फलन क्या हैं differential equations of second order and special functions in hindi

अध्याय - द्वितीय कोटि के अवकल समीकरण तथा विशिष्ट फलन (Differential Equations of Second Order…

1 day ago

four potential in hindi 4-potential electrodynamics चतुर्विम विभव किसे कहते हैं

चतुर्विम विभव (Four-Potential) हम जानते हैं कि एक निर्देश तंत्र में विद्युत क्षेत्र इसके सापेक्ष…

4 days ago

Relativistic Electrodynamics in hindi आपेक्षिकीय विद्युतगतिकी नोट्स क्या है परिभाषा

आपेक्षिकीय विद्युतगतिकी नोट्स क्या है परिभाषा Relativistic Electrodynamics in hindi ? अध्याय : आपेक्षिकीय विद्युतगतिकी…

6 days ago

pair production in hindi formula definition युग्म उत्पादन किसे कहते हैं परिभाषा सूत्र क्या है लिखिए

युग्म उत्पादन किसे कहते हैं परिभाषा सूत्र क्या है लिखिए pair production in hindi formula…

1 week ago

THRESHOLD REACTION ENERGY in hindi देहली अभिक्रिया ऊर्जा किसे कहते हैं सूत्र क्या है परिभाषा

देहली अभिक्रिया ऊर्जा किसे कहते हैं सूत्र क्या है परिभाषा THRESHOLD REACTION ENERGY in hindi…

1 week 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