File Handling in C Language | Full Guide in Telugu
Part-12: Data ni file lo ela save cheyali? - LearnTechSoft
💡 Real Life: Program close cheste data pothundi! Mari save cheyali ante? File lo rayali! Notepad lo data save chesinattu C lo file lo save chestam - Taruvata malli chadavachu!
1. File Handling Steps - 3 Steps
1. fopen()
File Open
File Open
2. fprintf() / fscanf()
Read / Write
Read / Write
3. fclose()
File Close
File Close
2. File Open Modes - Chala Important
| Mode | Meaning |
|---|---|
| "w" - Write | Rasthanu - File lekapothe kottha create, unte old delete |
| "r" - Read | Chaduvutanu - File undali compulsory |
| "a" - Append | Kottadi add chestanu - Old data undipotundi |
| "w+" - Read+Write | Rasi chadavachu |
3. Write to File - Full Program
#include <stdio.h>
int main() {
FILE *fp; // File Pointer
// Step 1: Open - "w" mode
fp = fopen("student.txt", "w");
if(fp == NULL) {
printf("File open error!");
return 1;
}
// Step 2: Write
fprintf(fp, "Name: Ramesh\n");
fprintf(fp, "Roll: 101\n");
fprintf(fp, "Marks: 85.5\n");
// Step 3: Close
fclose(fp);
printf("Data saved to student.txt successfully!");
return 0;
}
// Output: student.txt file create ayi data save avtundi
4. Read from File - Full Program
#include <stdio.h>
int main() {
FILE *fp;
char data[100];
// Step 1: Open - "r" mode
fp = fopen("student.txt", "r");
if(fp == NULL) {
printf("File not found!");
return 1;
}
// Step 2: Read - Line by line
printf("File Data:\n");
while(fgets(data, 100, fp) != NULL) {
printf("%s", data);
}
// Step 3: Close
fclose(fp);
return 0;
}
5. Real Project Idea
💡 Student Database Project:
Structure + File Handling kalipi - 60 students data ni file lo save cheyachu!
1. Structure - Student details
2. File - "w" tho save
3. File - "r" tho chaduvu - Report card print!
Idhe C Final Project - Interview lo adugutaru!
Structure + File Handling kalipi - 60 students data ni file lo save cheyachu!
1. Structure - Student details
2. File - "w" tho save
3. File - "r" tho chaduvu - Report card print!
Idhe C Final Project - Interview lo adugutaru!
🎉 CORE C LANGUAGE COMPLETE! - 12 Parts Done!
Next: C Important Programs - Reverse, Palindrome, Prime, Factorial -