DMCA.com Protection Status C Programming – Day 10 | File Handling in C Explained for Beginners - ZAREEN TECH WAVE -Largest Tutorials Website For Freelancer ZAREEN TECH WAVE -Largest Tutorials Website For Freelancer

Header Ads

C Programming – Day 10 | File Handling in C Explained for Beginners

FILE HANDLING IN C

DAY - 10


Learn C Programming Day 10 with a complete guide to file handling in C. Understand how to open, read, write, and close files, and work with text and binary files using clear examples for beginners.

✅ Let’s move to Day-10 — File Handling in C 🚀


📍 Day-10 — File Handling in C

Today we will learn:

✅ What is a file?
✅ Types of files in C
✅ File operations: open, read, write, close
✅ Reading and writing text files
✅ Task + Quiz


✅ 1️⃣ What is a File?

📌 A file is a collection of data stored on disk
📌 C allows programs to read/write files

Types:

  • Text File.txt (Human-readable)

  • Binary File.bin (Computer-readable)


✅ 2️⃣ File Operations in C

1️⃣ Open a filefopen()

FILE *fp; fp = fopen("data.txt", "w"); // w=write, r=read, a=append

2️⃣ Write to a filefprintf() or fputs()

fprintf(fp, "Hello File\n");

3️⃣ Read from a filefscanf() or fgets()

char str[50]; fgets(str, 50, fp);

4️⃣ Close the filefclose()

fclose(fp);

✅ 3️⃣ Example — Write & Read File

#include <stdio.h> int main() { FILE *fp; char name[30]; // Write fp = fopen("student.txt", "w"); printf("Enter your name: "); scanf("%s", name); fprintf(fp, "Name: %s\n", name); fclose(fp); // Read fp = fopen("student.txt", "r"); char line[50]; fgets(line, 50, fp); printf("File Content: %s", line); fclose(fp); return 0; }

✅ 4️⃣ File Modes in C

ModeMeaning
rRead only
wWrite only (overwrite)
aAppend
r+Read & write
w+Write & read (overwrite)
a+Append & read

✅ Task-10

Write a program:

✔ Create a file marks.txt
✔ Input marks of 3 students
✔ Write marks to file
✔ Read from the file and display on screen

Example Output:

Student 1 Marks: 88 Student 2 Marks: 92 Student 3 Marks: 79

📌 Hint: Use fprintf() for writing and fscanf() or fgets() for reading


📝 Quick Quiz — Day-10

Reply like: 1C, 2B, 3A

1️⃣ Function to open a file:
A) fopenfile()
B) open()
C) fopen()

2️⃣ Mode to append text to a file:
A) w
B) a
C) r

3️⃣ Function to close a file:
A) fclose()
B) closefile()
C) endfile()


📌 Reminder:

Send your Task-10 Code and Day-10 Quiz Answers when ready!

Then we will proceed to Day-11: Dynamic Memory Allocation in C 💪




C Programming Day 10 teaches file handling in C, including reading, writing, and managing files. Learn how to work with text and binary files using file pointers and standard C functions for beginner-friendly examples.

No comments

Thank You For Visit My Website.
I Will Contact As Soon As Possible.

Theme images by 5ugarless. Powered by Blogger.