Open navigation menu
Close suggestions
Search
Search
en
Change Language
Upload
Sign in
Sign in
Download free for days
0 ratings
0% found this document useful (0 votes)
6 views
File Handing
file handleing notes
Uploaded by
Rahul mandal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here
.
Available Formats
Download as PDF or read online on Scribd
Download now
Download
Save File Handing For Later
Download
Save
Save File Handing For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
0 ratings
0% found this document useful (0 votes)
6 views
File Handing
file handleing notes
Uploaded by
Rahul mandal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here
.
Available Formats
Download as PDF or read online on Scribd
Download now
Download
Save File Handing For Later
Carousel Previous
Carousel Next
Save
Save File Handing For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
Download now
Download
You are on page 1
/ 8
Search
Fullscreen
2 9 Page 2 /9 File handling (only if time is available, otherwise should be done as part of the lab) File handling in programming refers to the process of reading from and \arting to fles on 2 computer's storage. This allows programs to interact with extemal data, store Information persistently, and share deta between different executions of the program. File handling operations typlealy involve opening files, reading or writing data, and closing fles. Here are key concepts related to fle handling: Drag from top and touch the back button to exit full screen. © Scanned with OKEN ScannerPage 3 /9 He @ Q@ « > 1, File Operations: Opening a File: Use functions like f open to open a file for reading, writing, or both. Closing a File: Use f close to close an open file, ensuring that resources are released. 2. File Modes: Files can be opened in different modes: “r': Read mode rite mode (creates a new file or truncates an existing one) Append mode (writes to the end of the file) Binary mode (for handling binary files) "+": Read and write mode © Scanned with OKEN ScannerPage 4 mo fl we @ Q@ < > 3. Reading from a File: Use functions lke f scan f or f gets to read data from a fle The f get c function reads a single character. 4. Writing to a File: Use functions lke f print for f puts to write data to a file. ‘The fputc function writes a single character. 5, Binary File Handling: For handling binary files, use functions lke f read and f waite 6. Error Handling: Check the return values of fle handling functions for errors, Use functions tke fe of to check for the end ofa file © Scanned with OKEN ScannerPage 5 /9 AF @ A < > Z. File Positionina: Use functions Ike f seek and f tell to set and get the file position, 8. Text Vs. Binary Files: Text files store data as human-readable text. Binary files store data in a format that Is not human-readable, allowing for more efficient storage of complex data structures. 9. File Streams: Files are typically accessed through fle streams, such as FILE structures in languages ike C. File Handling is the storing of data in a file using a program. In CC programming language, the programs store results, and other data of the program to a file using file handling in C. Also, we can extracvfetch data from a file to work with It In the program. The operations that you can perform on a File in C are ~ + Creating a new file ‘© Opening an existing file Reading data from an existing file Writing data to a file Moving data to a specific location on the file © Scanned with OKEN ScannerPage 6 /9 Hove Q@ QA « > + Closing the file Creating Or Opening File Using F Open The f open () function is used to create a new file or open an existing file in C. The f open function is defined in the stdio.h header file. Now, lets see the syntax for creation of a new fle or opening a file file = f open(file _ name", “mode") This is a common syntax for both opening and creating a file in Cc. Parameters File _name - Itis a string that specifies the name of the file that is to be opened o created using the f open method, Mode : It is a string (usually a single character ) that specifies the mode in which the file is to be opened. There are various modes available to open a file in C, we will learn about all of them later in this article. When Will A File Be Created? © Scanned with OKEN Scanner2 2 Page 7 Jo Q The f open function will create a new file when it will not find any file of the specified name in the specified location. Else, if the file is found it will be opened with the mode specified. Let’s see can example which will make the concept clear, Suppose we are opening a file named hello.txt using the f open function. The following will be the statement, file = f open(‘hello.txt’, w") This will search for a file named hello.xt in the current directory. If the file exists, it will open the file otherwise it wil create a new file named “hello.txt" and open it with write mode (specified using *w’) Now, let's see all types of modes that are available for us to read or write a file in C, and see code snippets that will show sample runs of the code. Mode = ‘r" - open for reading, this mode will open the file for reading purpose only, i.e. the contents can only be viewed, nothing else like edits can be done to it. This mode cannot create a new file and open () retums NULL, if we try to create a new file using this mode. © Scanned with OKEN Scanner#include Puen oma FILE *sourceFile, *destinationFile; cr sourceFile = fopen( it (sourceFile == NULL) { Diced ag ae eam Vik oH Clete se eee Beale eC see eee oeaag Beate cere return EXIT_FAILURE; cen, while ((ch = fgete(sourceFile)) != EOF) ( sted cme Ula CO © Scanned with OKEN Scannerfclose(sourceFile) ; Brae 80-1808 pana The program opens a source file ("source.txt") in read mode and a destination file ("destination.txt’) in write mode It reads characters from the source file one by one and writes them to the destination file. The f get c function is used to read characters, and f put c is used to write characters. The loop continues until the end of the file (EOF) is reached After copying is complete, both files are closed © Scanned with OKEN Scanner
You might also like
File Handling With C
PDF
No ratings yet
File Handling With C
22 pages
File Handling
PDF
No ratings yet
File Handling
14 pages
File Handling in C
PDF
No ratings yet
File Handling in C
10 pages
File Handling in C
PDF
No ratings yet
File Handling in C
21 pages
Files in C
PDF
No ratings yet
Files in C
10 pages
Working With Files
PDF
No ratings yet
Working With Files
24 pages
C-File Operations
PDF
No ratings yet
C-File Operations
6 pages
CTSD2_UNIT-5_File Management in C
PDF
No ratings yet
CTSD2_UNIT-5_File Management in C
47 pages
File Management
PDF
No ratings yet
File Management
10 pages
File Handeling in C
PDF
No ratings yet
File Handeling in C
11 pages
LectureMaterial 3
PDF
No ratings yet
LectureMaterial 3
13 pages
Programming Assignment - 2
PDF
No ratings yet
Programming Assignment - 2
16 pages
UNIT IV 2 Files
PDF
No ratings yet
UNIT IV 2 Files
24 pages
Handling Files in C
PDF
No ratings yet
Handling Files in C
35 pages
Unit V - 2
PDF
No ratings yet
Unit V - 2
40 pages
File c1
PDF
No ratings yet
File c1
26 pages
C File Notes
PDF
No ratings yet
C File Notes
5 pages
UNIT 5 PC NOTES
PDF
No ratings yet
UNIT 5 PC NOTES
30 pages
File Handling
PDF
No ratings yet
File Handling
57 pages
FILE HANDLING
PDF
No ratings yet
FILE HANDLING
2 pages
C Session10
PDF
No ratings yet
C Session10
19 pages
File Handling in C
PDF
No ratings yet
File Handling in C
12 pages
File Handling in C
PDF
No ratings yet
File Handling in C
15 pages
Introduction to File Handling
PDF
No ratings yet
Introduction to File Handling
35 pages
PPSUC Notes Unit-5
PDF
No ratings yet
PPSUC Notes Unit-5
27 pages
File Handling in C - IBSC
PDF
No ratings yet
File Handling in C - IBSC
14 pages
Unit-10 PPS
PDF
No ratings yet
Unit-10 PPS
12 pages
File Handling in C
PDF
No ratings yet
File Handling in C
48 pages
Module 5 - Files
PDF
No ratings yet
Module 5 - Files
8 pages
File Handling
PDF
No ratings yet
File Handling
31 pages
problem solving using c full course paart 4
PDF
No ratings yet
problem solving using c full course paart 4
8 pages
OLevel 2 B4 CLang 28may20 SS
PDF
No ratings yet
OLevel 2 B4 CLang 28may20 SS
4 pages
File-Handling
PDF
No ratings yet
File-Handling
5 pages
C Pass Addresses and Pointers
PDF
No ratings yet
C Pass Addresses and Pointers
29 pages
PART 10
PDF
No ratings yet
PART 10
5 pages
File Handling In C
PDF
No ratings yet
File Handling In C
33 pages
File Handling
PDF
No ratings yet
File Handling
20 pages
Unit 5 PC QB Ans
PDF
No ratings yet
Unit 5 PC QB Ans
39 pages
Unit 5
PDF
No ratings yet
Unit 5
30 pages
unit5_9defff38-b601-4099-80e6-8a492b0f9aee
PDF
No ratings yet
unit5_9defff38-b601-4099-80e6-8a492b0f9aee
36 pages
23 PPSC Unit 4 FILEOperations
PDF
No ratings yet
23 PPSC Unit 4 FILEOperations
33 pages
Basic File Handling
PDF
No ratings yet
Basic File Handling
17 pages
file_handling_in_c_gate_notes_92 (1)
PDF
No ratings yet
file_handling_in_c_gate_notes_92 (1)
4 pages
File handling in C
PDF
No ratings yet
File handling in C
62 pages
13588839
PDF
No ratings yet
13588839
25 pages
C Unit 5
PDF
No ratings yet
C Unit 5
6 pages
Files Notes
PDF
No ratings yet
Files Notes
17 pages
Advance C Project Chapter 2 (Introduction To File Handling in C-Part 1)
PDF
No ratings yet
Advance C Project Chapter 2 (Introduction To File Handling in C-Part 1)
13 pages
C lecture 8.1
PDF
No ratings yet
C lecture 8.1
12 pages
FILE HANDLING
PDF
No ratings yet
FILE HANDLING
6 pages
C File Handling
PDF
No ratings yet
C File Handling
18 pages
Unit 8(updated)_repaired
PDF
No ratings yet
Unit 8(updated)_repaired
33 pages
UNIT V
PDF
No ratings yet
UNIT V
19 pages
Data Files.pptx
PDF
No ratings yet
Data Files.pptx
52 pages
Class XII (As Per CBSE Board) : Computer Science
PDF
No ratings yet
Class XII (As Per CBSE Board) : Computer Science
38 pages
Chapter 12 Files Management in C
PDF
No ratings yet
Chapter 12 Files Management in C
48 pages
lect5
PDF
No ratings yet
lect5
53 pages
lect4
PDF
No ratings yet
lect4
46 pages
lect6
PDF
No ratings yet
lect6
55 pages
DOC-20210427-WA0023. (1)
PDF
No ratings yet
DOC-20210427-WA0023. (1)
44 pages
Lect1
PDF
No ratings yet
Lect1
58 pages
cn ca1
PDF
No ratings yet
cn ca1
10 pages
Memory L
PDF
No ratings yet
Memory L
44 pages
Compilier Design Ca1
PDF
No ratings yet
Compilier Design Ca1
4 pages
Four Asysmptotic Notations
PDF
No ratings yet
Four Asysmptotic Notations
3 pages