08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
Introduction of file handling
1. INTRODUCTION TO FILE HANDLING
Presentation topic:-
Submitted by Guided by
Vikash Maurya 👨 👸
2. CONTENTS 👉
1⃣ What is file?
2⃣ Need of file in C programming.
3⃣ Data organization.
4⃣ File operations.
5⃣ Creating a new file by C.
6⃣ Writing, Reading and Append operation in the file.
7⃣ Closing a file.
3. WHAT IS FILE? 🤔
A file is a collection of related data that a computer
treats as a single unit.
Computer store files to secondary storage so that
the contents of files remain intact when a computer
shuts down.
When a computer reads a file, it copies the file from
the storage device to memory; when it writes to a
file, it transfers data from memory to the storage
device.
C uses a structure called FILE (defined in stdio.h)
to store the attributes of a file.
4. NEED OF FILE IN C PROGRAMMING 📂
Often it is not enough to just display the data on the
screen. Because if the data is large, only few of it
can be stored and displayed on the screen. Here
memory is volatile so the contents would be lost
once the program is terminated. So if we need the
same data we need to re-enter it or regenerate the
program. And to redo the process is time wasting.
And if we would have saved it to a media where the
data can be recoverable, it would help us. This
medium is usually a ‘file’ on the disk.
5. DATA ORGANIZATION 💻
Before we start doing input/output let us first find out
how data is organized on the disk. Here is the
solution-
Our program
C Library
functions
OS Disk
6. FILE OPERATIONS 🔧
There are different operations that can be carried out
in a file.
These are:
(a) Creation of a new file.
(b) Opening an existing file.
(c) Writing to a file.
(d) Reading form a file.
(e) Closing a file.
7. PROGRAM TO CREATE A FILE 📣
/* C program to create a file called emp.rec and store information
* about a person, in terms of his name, age and salary */
#include <stdio.h>
#include <conio.h>
void main()
{
FILE *fptr;
char name[20];
int age;
float salary;
/* open for writing */
fptr = fopen("emp.c", "w");
printf("Enter the name n");
scanf("%s", name);
fprintf(fptr, "Name = %sn", name);
printf("Enter the agen");
scanf("%d", &age);
fprintf(fptr, "Age = %dn", age);
printf("Enter the salaryn");
scanf("%f", &salary);
fprintf(fptr, "Salary = %.2fn", salary);
fclose(fptr);
}
17. CLOSING A FILE 🔓
When we finish with a mode, we need to close the
file before ending the program or beginning another
mode with that same file.
To close a file, we use fclose.