C Language | File Handling in Hindi ?

What is File Handling in C Language in Hindi – फाइल हैंडलिंग क्या होती है ?


C language में जब Programmer , program को बंद करता है, तब program का सारा data destroy हो जाता है | अर्थात data permanently store नहीं होता | Data को permanently store करने के लिए ही File Handling का इस्तेमाल होता है | File Handling Concept हमें अपने डेटा को सेकेंडरी मेमोरी (हार्ड डिस्क) में permanently store करने में मदद करता है।

File Handling Concept का उपयोग करके हम एक file में बहुत सारें operations (कार्य) कर सकते हैं जैसे कि –

  • Create a  new file
  • Opening an  existing file
  • Reading  the file
  • Writing to the file
  • Deleting the file   etc.

इन operations को करने लिए हमारे पास बहुत सारे फंक्शन उपलब्ध है।

Function Use in File Handling :


File Handling के Functions का उपयोग करने के लिए stdio.h इस header file को include करना पड़ता है |

No. Function Description
1 fopen() opens new or existing file
2 fclose() closes the file
3 fprintf() write data into the file
4 fscanf() reads data from the file
5 fputc() writes a character into the file
6 fgetc() reads a character from file
7 fseek() sets the file pointer to given position
8 fputw() writes an integer to file
9 fgetw() reads an integer from file
10 ftell() returns current position
11 rewind() sets the file pointer to the beginning of the file

File को open करने के लिए कुछ ‘modes’ होते है |

Mode Description
r opens a text file in read mode
w opens a text file in write mode
a opens a text file in append mode
r+ opens a text file in read and write mode
w+ opens a text file in read and write mode
a+ opens a text file in read and write mode
rb opens a binary file in read mode
wb opens a binary file in write mode
ab opens a binary file in append mode
rb+ opens a binary file in read and write mode
wb+ opens a binary file in read and write mode
ab+ opens a binary file in read and write mode

File handling | fopen() function :


fopen() फंक्शन का प्रयोग फाइल को open करने के लिए किया जाता है |

Syntax for fopen() function :
file_pointer = fopen("file_name", "mode_of_file");

file_pointer : ये एक file pointer है जिसका data type ‘FILE’ है |
file_name : File का नाम। जैसे की file1.txt, file2.docx , .txt और .docx ये files के extensions है |
mode_of_file : File को किस mode से open करना है |

File handling | fclose() function :


fclose() फंक्शन का प्रयोग फाइल को close करने के लिए किया जाता है |

Syntax for fclose() function :
fclose(file_pointer);
Example of fopen() & fclose() function :

# include <stdio.h>

int main()
{

FILE * fptr;

fptr = fopen("Example.txt", "r");

fclose(fptr);

return 0;
}

File handling | fprintf() function :


fprintf() funtion से File में data को write किया जाता है |

Syntax for fprintf() function :
fprintf(file_pointer, "format_specifier or string", variables);

 

File handling | fscanf() function :


fscanf() funtion से File में data को read किया जाता है |

Syntax for fscanf() function :
fscanf(file_pointer, "format_specifier or string", &variables);