SlideShare a Scribd company logo
2
Most read
12
Most read
File Management and Preprocessor
Directives in C/C++
An introduction to file handling, macros, file inclusion, and compiler control.
Presented by
‱ Abhay Panchal,
‱ Hardi Zala,
‱ Roshni Rajput,
‱ Kuldeep Makwana,
‱ Umang Vaghela.
Faculty: Mitisha Barot. Date: 12-04-2025.
Introduction to File Management
1 Data Storage
Enables data storage and retrieval
for later use.
2 Configuration
Stores user input, logs, or
configuration files easily.
3 Persistence
Keeps data available even after
the program terminates.
File Types in C Language
Text Files
Human-readable files, such as .txt files.
Binary Files
Machine-readable files, such as .bin files.
We'll focus on text files for simplicity.
Basic File Operations (Text Files)
#include <stdio.h>
int main() {
FILE *fptr = fopen("file.txt", "w");
fprintf(fptr, "Hello, World!");
fclose(fptr);
return 0;
}
fopen() opens a new file. w mode creates or overwrites. fprintf writes formatted data. fclose saves changes.
Reading and Writing to Files
#include <stdio.h>
int main() {
FILE *f = fopen("file.txt", "r");
char buffer[100];
fgets(buffer, 100, f);
printf("%s", buffer);
fclose(f);
return 0;
}
r mode opens an existing file for reading. fgets reads a line into the buffer.
File Inclusion
System Files
Use angle brackets, like #include
<stdio.h>.
User Files
Use double quotes, like #include
"myfile.h".
Benefits
Inclusion allows code reuse and cleaner
files.
Example
Myfile.h
#ifndef MYFILE_H
#define MYFILE_H
#define MESSAGE "Hello from
myfile.h!"
void greet();
#endif
Main.c
#include <stdio.h>
#include "myfile.h"
int main() {
greet();
return 0;
}
Myfile.c
#include <stdio.h>
#include "myfile.h"
void greet() {
printf("%sn", MESSAGE);
}
Introduction to Preprocessor Directives
Timing
Handled before the actual
compilation process.
Purpose
Help in code reusability,
configuration, and modularization.
Examples
Macros, file inclusion, and
conditional compilation.
Macro Substitution
#define PI 3.14159
#define SQUARE(x) ((x)*(x))
1 PI
PI replaces every instance with
3.14159.
2 SQUARE(x)
SQUARE(x) becomes ((x)*(x))
after preprocessing.
3 Benefits
Improves readability and reduces
code repetition.
Compiler Control Directives
#define DEBUG
#ifdef DEBUG
printf("Debug mode ONn");
#endif
Code within #ifdef runs only if DEBUG is defined.
Useful for toggling debug logs or enabling testing features.
Summary
‱ File management helps persist data.
‱ fopen, fclose, fprintf, fgets are core file functions.
‱ Preprocessor directives enhance flexibility and modularity:
- #define for constants/macros
- #include for modularity
- #ifdef for conditional compilation
LDP-2 UNIT 4 Presentation for practical.pptx

More Related Content

Similar to LDP-2 UNIT 4 Presentation for practical.pptx (20)

PDF
VIT351 Software Development VI Unit5
YOGESH SINGH
 
PPTX
PPS-II UNIT-5 PPT.pptx
VenkataRangaRaoKommi1
 
PPTX
File management
sumathiv9
 
PDF
FILES IN C
yndaravind
 
PPTX
File handing in C
shrishcg
 
PPT
How to do file-handling - in C language
SwatiAtulJoshi
 
PPTX
File handling in c Programming - Unit 5.1
Priyadarshini803769
 
PDF
File Handling in C Programming
RavindraSalunke3
 
PPTX
INput output stream in ccP Full Detail.pptx
AssadLeo1
 
PPTX
File Handling
AlgeronTongdoTopi
 
PPTX
Topic - File operation.pptx
Adnan al-emran
 
PDF
EASY UNDERSTANDING OF FILES IN C LANGUAGE.pdf
sudhakargeruganti
 
PPT
File in c
Prabhu Govind
 
PPTX
PPS PPT 2.pptx
Sandeepbhuma1
 
PPTX
File handling in C
Simplilearn
 
DOCX
Files let you store data on secondary storage such as a hard disk so that you...
Bern Jamie
 
PPT
file_handling_in_c.ppt
yuvrajkeshri
 
PPTX
C-FILE MANAGEMENT.pptx
banu236831
 
PPT
file_handling_in_c.ppt
DHARUNESHBOOPATHY
 
PPTX
want to learn files,then just use this ppt to learn
nalluribalaji157
 
VIT351 Software Development VI Unit5
YOGESH SINGH
 
PPS-II UNIT-5 PPT.pptx
VenkataRangaRaoKommi1
 
File management
sumathiv9
 
FILES IN C
yndaravind
 
File handing in C
shrishcg
 
How to do file-handling - in C language
SwatiAtulJoshi
 
File handling in c Programming - Unit 5.1
Priyadarshini803769
 
File Handling in C Programming
RavindraSalunke3
 
INput output stream in ccP Full Detail.pptx
AssadLeo1
 
File Handling
AlgeronTongdoTopi
 
Topic - File operation.pptx
Adnan al-emran
 
EASY UNDERSTANDING OF FILES IN C LANGUAGE.pdf
sudhakargeruganti
 
File in c
Prabhu Govind
 
PPS PPT 2.pptx
Sandeepbhuma1
 
File handling in C
Simplilearn
 
Files let you store data on secondary storage such as a hard disk so that you...
Bern Jamie
 
file_handling_in_c.ppt
yuvrajkeshri
 
C-FILE MANAGEMENT.pptx
banu236831
 
file_handling_in_c.ppt
DHARUNESHBOOPATHY
 
want to learn files,then just use this ppt to learn
nalluribalaji157
 

Recently uploaded (20)

PPTX
Artificial Intelligence in Gastroentrology: Advancements and Future Presprec...
AyanHossain
 
PPTX
Applied-Statistics-1.pptx hardiba zalaaa
hardizala899
 
PPTX
Top 10 AI Tools, Like ChatGPT. You Must Learn In 2025
Digilearnings
 
PDF
My Thoughts On Q&A- A Novel By Vikas Swarup
Niharika
 
PDF
TOP 10 AI TOOLS YOU MUST LEARN TO SURVIVE IN 2025 AND ABOVE
digilearnings.com
 
PPTX
Python-Application-in-Drug-Design by R D Jawarkar.pptx
Rahul Jawarkar
 
PPTX
Unlock the Power of Cursor AI: MuleSoft Integrations
Veera Pallapu
 
PPTX
Gupta Art & Architecture Temple and Sculptures.pptx
Virag Sontakke
 
PPTX
Basics and rules of probability with real-life uses
ravatkaran694
 
PPTX
IDEAS AND EARLY STATES Social science pptx
NIRANJANASSURESH
 
PPTX
Continental Accounting in Odoo 18 - Odoo Slides
Celine George
 
DOCX
Unit 5: Speech-language and swallowing disorders
JELLA VISHNU DURGA PRASAD
 
PDF
EXCRETION-STRUCTURE OF NEPHRON,URINE FORMATION
raviralanaresh2
 
PPTX
PROTIEN ENERGY MALNUTRITION: NURSING MANAGEMENT.pptx
PRADEEP ABOTHU
 
PPTX
INTESTINALPARASITES OR WORM INFESTATIONS.pptx
PRADEEP ABOTHU
 
PDF
BÀI TáșŹP TEST BỔ TRỹ THEO Tá»ȘNG CHỊ ĐỀ CỊA Tá»ȘNG UNIT KÈM BÀI TáșŹP NGHE - TIáșŸNG A...
Nguyen Thanh Tu Collection
 
PPTX
TOP 10 AI TOOLS YOU MUST LEARN TO SURVIVE IN 2025 AND ABOVE
digilearnings.com
 
PPTX
Introduction to pediatric nursing in 5th Sem..pptx
AneetaSharma15
 
PPT
DRUGS USED IN THERAPY OF SHOCK, Shock Therapy, Treatment or management of shock
Rajshri Ghogare
 
PPTX
Cybersecurity: How to Protect your Digital World from Hackers
vaidikpanda4
 
Artificial Intelligence in Gastroentrology: Advancements and Future Presprec...
AyanHossain
 
Applied-Statistics-1.pptx hardiba zalaaa
hardizala899
 
Top 10 AI Tools, Like ChatGPT. You Must Learn In 2025
Digilearnings
 
My Thoughts On Q&A- A Novel By Vikas Swarup
Niharika
 
TOP 10 AI TOOLS YOU MUST LEARN TO SURVIVE IN 2025 AND ABOVE
digilearnings.com
 
Python-Application-in-Drug-Design by R D Jawarkar.pptx
Rahul Jawarkar
 
Unlock the Power of Cursor AI: MuleSoft Integrations
Veera Pallapu
 
Gupta Art & Architecture Temple and Sculptures.pptx
Virag Sontakke
 
Basics and rules of probability with real-life uses
ravatkaran694
 
IDEAS AND EARLY STATES Social science pptx
NIRANJANASSURESH
 
Continental Accounting in Odoo 18 - Odoo Slides
Celine George
 
Unit 5: Speech-language and swallowing disorders
JELLA VISHNU DURGA PRASAD
 
EXCRETION-STRUCTURE OF NEPHRON,URINE FORMATION
raviralanaresh2
 
PROTIEN ENERGY MALNUTRITION: NURSING MANAGEMENT.pptx
PRADEEP ABOTHU
 
INTESTINALPARASITES OR WORM INFESTATIONS.pptx
PRADEEP ABOTHU
 
BÀI TáșŹP TEST BỔ TRỹ THEO Tá»ȘNG CHỊ ĐỀ CỊA Tá»ȘNG UNIT KÈM BÀI TáșŹP NGHE - TIáșŸNG A...
Nguyen Thanh Tu Collection
 
TOP 10 AI TOOLS YOU MUST LEARN TO SURVIVE IN 2025 AND ABOVE
digilearnings.com
 
Introduction to pediatric nursing in 5th Sem..pptx
AneetaSharma15
 
DRUGS USED IN THERAPY OF SHOCK, Shock Therapy, Treatment or management of shock
Rajshri Ghogare
 
Cybersecurity: How to Protect your Digital World from Hackers
vaidikpanda4
 
Ad

LDP-2 UNIT 4 Presentation for practical.pptx

  • 1. File Management and Preprocessor Directives in C/C++ An introduction to file handling, macros, file inclusion, and compiler control. Presented by ‱ Abhay Panchal, ‱ Hardi Zala, ‱ Roshni Rajput, ‱ Kuldeep Makwana, ‱ Umang Vaghela. Faculty: Mitisha Barot. Date: 12-04-2025.
  • 2. Introduction to File Management 1 Data Storage Enables data storage and retrieval for later use. 2 Configuration Stores user input, logs, or configuration files easily. 3 Persistence Keeps data available even after the program terminates.
  • 3. File Types in C Language Text Files Human-readable files, such as .txt files. Binary Files Machine-readable files, such as .bin files. We'll focus on text files for simplicity.
  • 4. Basic File Operations (Text Files) #include <stdio.h> int main() { FILE *fptr = fopen("file.txt", "w"); fprintf(fptr, "Hello, World!"); fclose(fptr); return 0; } fopen() opens a new file. w mode creates or overwrites. fprintf writes formatted data. fclose saves changes.
  • 5. Reading and Writing to Files #include <stdio.h> int main() { FILE *f = fopen("file.txt", "r"); char buffer[100]; fgets(buffer, 100, f); printf("%s", buffer); fclose(f); return 0; } r mode opens an existing file for reading. fgets reads a line into the buffer.
  • 6. File Inclusion System Files Use angle brackets, like #include <stdio.h>. User Files Use double quotes, like #include "myfile.h". Benefits Inclusion allows code reuse and cleaner files.
  • 7. Example Myfile.h #ifndef MYFILE_H #define MYFILE_H #define MESSAGE "Hello from myfile.h!" void greet(); #endif Main.c #include <stdio.h> #include "myfile.h" int main() { greet(); return 0; } Myfile.c #include <stdio.h> #include "myfile.h" void greet() { printf("%sn", MESSAGE); }
  • 8. Introduction to Preprocessor Directives Timing Handled before the actual compilation process. Purpose Help in code reusability, configuration, and modularization. Examples Macros, file inclusion, and conditional compilation.
  • 9. Macro Substitution #define PI 3.14159 #define SQUARE(x) ((x)*(x)) 1 PI PI replaces every instance with 3.14159. 2 SQUARE(x) SQUARE(x) becomes ((x)*(x)) after preprocessing. 3 Benefits Improves readability and reduces code repetition.
  • 10. Compiler Control Directives #define DEBUG #ifdef DEBUG printf("Debug mode ONn"); #endif Code within #ifdef runs only if DEBUG is defined. Useful for toggling debug logs or enabling testing features.
  • 11. Summary ‱ File management helps persist data. ‱ fopen, fclose, fprintf, fgets are core file functions. ‱ Preprocessor directives enhance flexibility and modularity: - #define for constants/macros - #include for modularity - #ifdef for conditional compilation