SlideShare a Scribd company logo
Disk File Input and Output
• A file can refer to a disk file, a terminal, a printer, or a tape drive.
• Stream is data flow you transfer from your program to a file, or vice versa.
• buffer is a memory area, which is temporarily used to store data before it is sent to
its destination.
• Step of file
– Opening a File
FILE *fopen(char *filename,char *mode);
– Closing a File
fclose(*pfile);
Note:
• "w" Open text file for write operations. If the file exists, its current contents are
discarded.
• "a" Open a text file for append operations. All writes are to the end of the file.
• "r" Open a text file for read operations.
Writing to a Text File
Reading from a Text File
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
const int LENGTH = 80; /* Maximum input length */
int main(void)
{
char mystr[LENGTH]; /* Input string */
int lstr = 0; /* Length of input string */
int mychar = 0; /* Character for output */
FILE *pfile = NULL; /* File pointer */
char *filename = "C:myfile.txt";
printf("nEnter string of less than 80 characters:n");
fgets(mystr, LENGTH, stdin); /* Read in a string */
/* Create a new file we can write */
if(!(pfile = fopen(filename, "w")))
{
printf("Error %s for writing. ", filename);
exit(1);
}
lstr = strlen(mystr);
for(int i = lstr-1 ; i >= 0 ; i--)
fputc(mystr[i], pfile); /* Write string to file */
fclose(pfile); /* Close the file */
/* Open the file for reading */
if(!(pfile = fopen(filename, "r")))
{
printf("Error opening %s for reading. Program
terminated.", filename);
exit(1);
}
/* Read a character from the file and display it */
while((mychar = fgetc(pfile)) != EOF)
putchar(mychar); /* Output character
from the file */
putchar('n'); /* Write newline
*/
fclose(pfile); /* Close the file
*/
remove(filename); /* Delete the physical
file */
return 0;
}
/* 21L02.c: Reading and writing one character at a time */
#include <stdio.h>
enum {SUCCESS, FAIL};
void CharReadWrite(FILE *fin, FILE *fout);
main(void)
{
FILE *fptr1, *fptr2;
char filename1[]= "outhaiku.txt";
char filename2[]= "haiku.txt";
int reval = SUCCESS;
if ((fptr1 = fopen(filename1, "w")) == NULL){
printf("Cannot open %s.n", filename1);
reval = FAIL;
} else if ((fptr2 = fopen(filename2, "r")) == NULL){
printf("Cannot open %s.n", filename2);
reval = FAIL;
} else {
CharReadWrite(fptr2, fptr1);
fclose(fptr1);
fclose(fptr2);
}
return reval;
}
/* function definition */
void CharReadWrite(FILE *fin, FILE
*fout)
{
int c;
while ((c=fgetc(fin)) != EOF){
fputc(c, fout); /* write to a file */
putchar(c); /* put the character
on the screen */
}
}
/* 21L03.c: Reading and writing one line at a time */
#include <stdio.h>
enum {SUCCESS, FAIL, MAX_LEN = 81};
void LineReadWrite(FILE *fin, FILE *fout);
main(void)
{
FILE *fptr1, *fptr2;
char filename1[]= "outhaiku.txt";
char filename2[]= "haiku.txt";
int reval = SUCCESS;
if ((fptr1 = fopen(filename1, "w")) == NULL){
printf("Cannot open %s for writing.n", filename1);
reval = FAIL;
} else if ((fptr2 = fopen(filename2, "r")) == NULL){
printf("Cannot open %s for reading.n", filename2);
reval = FAIL;
} else {
LineReadWrite(fptr2, fptr1);
fclose(fptr1);
fclose(fptr2);
}
return reval;
}
/* function definition */
void LineReadWrite(FILE *fin, FILE *fout)
{
char buff[MAX_LEN];
while (fgets(buff, MAX_LEN, fin) !=
NULL){
fputs(buff, fout);
printf("%s", buff);
}
}

More Related Content

What's hot

File Management in C
File Management in CFile Management in C
File Management in C
Paurav Shah
 
File handling in C
File handling in CFile handling in C
File handling in C
Kamal Acharya
 
File handling in c
File  handling in cFile  handling in c
File handling in c
thirumalaikumar3
 
Module 03 File Handling in C
Module 03 File Handling in CModule 03 File Handling in C
Module 03 File Handling in C
Tushar B Kute
 
File handling-c programming language
File handling-c programming languageFile handling-c programming language
File handling-c programming language
thirumalaikumar3
 
File handling-dutt
File handling-duttFile handling-dutt
File handling-dutt
Anil Dutt
 
File Handling in C
File Handling in C File Handling in C
File Handling in C
Subhanshu Maurya
 
File handling in C by Faixan
File handling in C by FaixanFile handling in C by Faixan
File handling in C by Faixan
ٖFaiXy :)
 
C programming file handling
C  programming file handlingC  programming file handling
C programming file handling
argusacademy
 
File handling in 'C'
File handling in 'C'File handling in 'C'
File handling in 'C'
Gaurav Garg
 
File in C language
File in C languageFile in C language
File in C language
Manash Kumar Mondal
 
File operations in c
File operations in cFile operations in c
File handling C program
File handling C programFile handling C program
File handling C program
Thesis Scientist Private Limited
 
Programming in C Session 4
Programming in C Session 4Programming in C Session 4
Programming in C Session 4
Prerna Sharma
 
File in C Programming
File in C ProgrammingFile in C Programming
File in C Programming
Sonya Akter Rupa
 
File handling in c
File handling in cFile handling in c
File handling in c
David Livingston J
 
C Programming Unit-5
C Programming Unit-5C Programming Unit-5
C Programming Unit-5
Vikram Nandini
 
File handling in C
File handling in CFile handling in C
File handling in C
Rabin BK
 
Understanding c file handling functions with examples
Understanding c file handling functions with examplesUnderstanding c file handling functions with examples
Understanding c file handling functions with examples
Muhammed Thanveer M
 
File handling-c
File handling-cFile handling-c

What's hot (20)

File Management in C
File Management in CFile Management in C
File Management in C
 
File handling in C
File handling in CFile handling in C
File handling in C
 
File handling in c
File  handling in cFile  handling in c
File handling in c
 
Module 03 File Handling in C
Module 03 File Handling in CModule 03 File Handling in C
Module 03 File Handling in C
 
File handling-c programming language
File handling-c programming languageFile handling-c programming language
File handling-c programming language
 
File handling-dutt
File handling-duttFile handling-dutt
File handling-dutt
 
File Handling in C
File Handling in C File Handling in C
File Handling in C
 
File handling in C by Faixan
File handling in C by FaixanFile handling in C by Faixan
File handling in C by Faixan
 
C programming file handling
C  programming file handlingC  programming file handling
C programming file handling
 
File handling in 'C'
File handling in 'C'File handling in 'C'
File handling in 'C'
 
File in C language
File in C languageFile in C language
File in C language
 
File operations in c
File operations in cFile operations in c
File operations in c
 
File handling C program
File handling C programFile handling C program
File handling C program
 
Programming in C Session 4
Programming in C Session 4Programming in C Session 4
Programming in C Session 4
 
File in C Programming
File in C ProgrammingFile in C Programming
File in C Programming
 
File handling in c
File handling in cFile handling in c
File handling in c
 
C Programming Unit-5
C Programming Unit-5C Programming Unit-5
C Programming Unit-5
 
File handling in C
File handling in CFile handling in C
File handling in C
 
Understanding c file handling functions with examples
Understanding c file handling functions with examplesUnderstanding c file handling functions with examples
Understanding c file handling functions with examples
 
File handling-c
File handling-cFile handling-c
File handling-c
 

Viewers also liked

پایش مراکز تجاری سازی در سطح بین المللی (مراکز خدمات کسب و کار)
پایش مراکز تجاری سازی در سطح بین المللی (مراکز خدمات کسب و کار)پایش مراکز تجاری سازی در سطح بین المللی (مراکز خدمات کسب و کار)
پایش مراکز تجاری سازی در سطح بین المللی (مراکز خدمات کسب و کار)
Alireza Masjedian علیرضا مسجدیان
 
Mahmoud Nasr
Mahmoud NasrMahmoud Nasr
Mahmoud Nasr
Mahmoud Nasr El-Din
 
Andrew Fairbanks CV
Andrew Fairbanks CVAndrew Fairbanks CV
Andrew Fairbanks CV
Andrew Fairbanks
 
ROWAD Seminars |How to Become an Online Freelancer.
ROWAD Seminars |How to Become an Online Freelancer.ROWAD Seminars |How to Become an Online Freelancer.
ROWAD Seminars |How to Become an Online Freelancer.
ROWAD Foundation
 
12 THINGS
12 THINGS12 THINGS
12 THINGS
slouchiha
 
Job design and job evaluation
Job design and job evaluationJob design and job evaluation
Job design and job evaluation
sravankumar dasari
 
مخاطر الإنترنت على أبنائنا
مخاطر الإنترنت على أبنائنامخاطر الإنترنت على أبنائنا
مخاطر الإنترنت على أبنائنا
Saif Albadi
 
Man power planning
Man power planning Man power planning
Man power planning
gihan aboueleish
 

Viewers also liked (8)

پایش مراکز تجاری سازی در سطح بین المللی (مراکز خدمات کسب و کار)
پایش مراکز تجاری سازی در سطح بین المللی (مراکز خدمات کسب و کار)پایش مراکز تجاری سازی در سطح بین المللی (مراکز خدمات کسب و کار)
پایش مراکز تجاری سازی در سطح بین المللی (مراکز خدمات کسب و کار)
 
Mahmoud Nasr
Mahmoud NasrMahmoud Nasr
Mahmoud Nasr
 
Andrew Fairbanks CV
Andrew Fairbanks CVAndrew Fairbanks CV
Andrew Fairbanks CV
 
ROWAD Seminars |How to Become an Online Freelancer.
ROWAD Seminars |How to Become an Online Freelancer.ROWAD Seminars |How to Become an Online Freelancer.
ROWAD Seminars |How to Become an Online Freelancer.
 
12 THINGS
12 THINGS12 THINGS
12 THINGS
 
Job design and job evaluation
Job design and job evaluationJob design and job evaluation
Job design and job evaluation
 
مخاطر الإنترنت على أبنائنا
مخاطر الإنترنت على أبنائنامخاطر الإنترنت على أبنائنا
مخاطر الإنترنت على أبنائنا
 
Man power planning
Man power planning Man power planning
Man power planning
 

Similar to 6. chapter v

File management and handling by prabhakar
File management and handling by prabhakarFile management and handling by prabhakar
File management and handling by prabhakar
PrabhakarPremUpreti
 
File management
File managementFile management
File management
lalithambiga kamaraj
 
PPS PPT 2.pptx
PPS PPT 2.pptxPPS PPT 2.pptx
PPS PPT 2.pptx
Sandeepbhuma1
 
Files_in_C.ppt
Files_in_C.pptFiles_in_C.ppt
Files_in_C.ppt
kasthurimukila
 
C-Programming File-handling-C.pptx
C-Programming  File-handling-C.pptxC-Programming  File-handling-C.pptx
C-Programming File-handling-C.pptx
LECO9
 
C-Programming File-handling-C.pptx
C-Programming  File-handling-C.pptxC-Programming  File-handling-C.pptx
C-Programming File-handling-C.pptx
SKUP1
 
Engineering Computers L34-L35-File Handling.pptx
Engineering Computers L34-L35-File Handling.pptxEngineering Computers L34-L35-File Handling.pptx
Engineering Computers L34-L35-File Handling.pptx
happycocoman
 
637225560972186380.pdf
637225560972186380.pdf637225560972186380.pdf
637225560972186380.pdf
SureshKalirawna
 
EASY UNDERSTANDING OF FILES IN C LANGUAGE.pdf
EASY UNDERSTANDING OF FILES IN C LANGUAGE.pdfEASY UNDERSTANDING OF FILES IN C LANGUAGE.pdf
EASY UNDERSTANDING OF FILES IN C LANGUAGE.pdf
sudhakargeruganti
 
Unit5 C
Unit5 C Unit5 C
Unit5 C
arnold 7490
 
File Handling in C Programming for Beginners
File Handling in C Programming for BeginnersFile Handling in C Programming for Beginners
File Handling in C Programming for Beginners
VSKAMCSPSGCT
 
file_handling_in_c.ppt
file_handling_in_c.pptfile_handling_in_c.ppt
file_handling_in_c.ppt
yuvrajkeshri
 
C-Programming Chapter 5 File-handling-C.ppt
C-Programming Chapter 5 File-handling-C.pptC-Programming Chapter 5 File-handling-C.ppt
C-Programming Chapter 5 File-handling-C.ppt
ssuserad38541
 
Unit 8
Unit 8Unit 8
C-FILE MANAGEMENT.pptx
C-FILE MANAGEMENT.pptxC-FILE MANAGEMENT.pptx
C-FILE MANAGEMENT.pptx
banu236831
 
File_Handling in C.ppt
File_Handling in C.pptFile_Handling in C.ppt
File_Handling in C.ppt
lakshmanarao027MVGRC
 
File_Handling in C.ppt
File_Handling in C.pptFile_Handling in C.ppt
File_Handling in C.ppt
lakshmanarao027MVGRC
 
UNIT 10. Files and file handling in C
UNIT 10. Files and file handling in CUNIT 10. Files and file handling in C
UNIT 10. Files and file handling in C
Ashim Lamichhane
 
Unit5
Unit5Unit5
Unit5
mrecedu
 
Lecture 20 - File Handling
Lecture 20 - File HandlingLecture 20 - File Handling
Lecture 20 - File Handling
Md. Imran Hossain Showrov
 

Similar to 6. chapter v (20)

File management and handling by prabhakar
File management and handling by prabhakarFile management and handling by prabhakar
File management and handling by prabhakar
 
File management
File managementFile management
File management
 
PPS PPT 2.pptx
PPS PPT 2.pptxPPS PPT 2.pptx
PPS PPT 2.pptx
 
Files_in_C.ppt
Files_in_C.pptFiles_in_C.ppt
Files_in_C.ppt
 
C-Programming File-handling-C.pptx
C-Programming  File-handling-C.pptxC-Programming  File-handling-C.pptx
C-Programming File-handling-C.pptx
 
C-Programming File-handling-C.pptx
C-Programming  File-handling-C.pptxC-Programming  File-handling-C.pptx
C-Programming File-handling-C.pptx
 
Engineering Computers L34-L35-File Handling.pptx
Engineering Computers L34-L35-File Handling.pptxEngineering Computers L34-L35-File Handling.pptx
Engineering Computers L34-L35-File Handling.pptx
 
637225560972186380.pdf
637225560972186380.pdf637225560972186380.pdf
637225560972186380.pdf
 
EASY UNDERSTANDING OF FILES IN C LANGUAGE.pdf
EASY UNDERSTANDING OF FILES IN C LANGUAGE.pdfEASY UNDERSTANDING OF FILES IN C LANGUAGE.pdf
EASY UNDERSTANDING OF FILES IN C LANGUAGE.pdf
 
Unit5 C
Unit5 C Unit5 C
Unit5 C
 
File Handling in C Programming for Beginners
File Handling in C Programming for BeginnersFile Handling in C Programming for Beginners
File Handling in C Programming for Beginners
 
file_handling_in_c.ppt
file_handling_in_c.pptfile_handling_in_c.ppt
file_handling_in_c.ppt
 
C-Programming Chapter 5 File-handling-C.ppt
C-Programming Chapter 5 File-handling-C.pptC-Programming Chapter 5 File-handling-C.ppt
C-Programming Chapter 5 File-handling-C.ppt
 
Unit 8
Unit 8Unit 8
Unit 8
 
C-FILE MANAGEMENT.pptx
C-FILE MANAGEMENT.pptxC-FILE MANAGEMENT.pptx
C-FILE MANAGEMENT.pptx
 
File_Handling in C.ppt
File_Handling in C.pptFile_Handling in C.ppt
File_Handling in C.ppt
 
File_Handling in C.ppt
File_Handling in C.pptFile_Handling in C.ppt
File_Handling in C.ppt
 
UNIT 10. Files and file handling in C
UNIT 10. Files and file handling in CUNIT 10. Files and file handling in C
UNIT 10. Files and file handling in C
 
Unit5
Unit5Unit5
Unit5
 
Lecture 20 - File Handling
Lecture 20 - File HandlingLecture 20 - File Handling
Lecture 20 - File Handling
 

More from Chhom Karath

set1.pdf
set1.pdfset1.pdf
set1.pdf
Chhom Karath
 
Set1.pptx
Set1.pptxSet1.pptx
Set1.pptx
Chhom Karath
 
orthodontic patient education.pdf
orthodontic patient education.pdforthodontic patient education.pdf
orthodontic patient education.pdf
Chhom Karath
 
New ton 3.pdf
New ton 3.pdfNew ton 3.pdf
New ton 3.pdf
Chhom Karath
 
ច្បាប់ញូតុនទី៣.pptx
ច្បាប់ញូតុនទី៣.pptxច្បាប់ញូតុនទី៣.pptx
ច្បាប់ញូតុនទី៣.pptx
Chhom Karath
 
Control tipping.pptx
Control tipping.pptxControl tipping.pptx
Control tipping.pptx
Chhom Karath
 
Bulbous loop.pptx
Bulbous loop.pptxBulbous loop.pptx
Bulbous loop.pptx
Chhom Karath
 
brush teeth.pptx
brush teeth.pptxbrush teeth.pptx
brush teeth.pptx
Chhom Karath
 
bracket size.pptx
bracket size.pptxbracket size.pptx
bracket size.pptx
Chhom Karath
 
arch form KORI copy.pptx
arch form KORI copy.pptxarch form KORI copy.pptx
arch form KORI copy.pptx
Chhom Karath
 
Bracket size
Bracket sizeBracket size
Bracket size
Chhom Karath
 
Couple
CoupleCouple
Couple
Chhom Karath
 
ច្បាប់ញូតុនទី៣
ច្បាប់ញូតុនទី៣ច្បាប់ញូតុនទី៣
ច្បាប់ញូតុនទី៣
Chhom Karath
 
Game1
Game1Game1
Shoe horn loop
Shoe horn loopShoe horn loop
Shoe horn loop
Chhom Karath
 
Opus loop
Opus loopOpus loop
Opus loop
Chhom Karath
 
V bend
V bendV bend
V bend
Chhom Karath
 
Closing loop
Closing loopClosing loop
Closing loop
Chhom Karath
 
Maxillary arch form
Maxillary arch formMaxillary arch form
Maxillary arch form
Chhom Karath
 
Front face analysis
Front face analysisFront face analysis
Front face analysis
Chhom Karath
 

More from Chhom Karath (20)

set1.pdf
set1.pdfset1.pdf
set1.pdf
 
Set1.pptx
Set1.pptxSet1.pptx
Set1.pptx
 
orthodontic patient education.pdf
orthodontic patient education.pdforthodontic patient education.pdf
orthodontic patient education.pdf
 
New ton 3.pdf
New ton 3.pdfNew ton 3.pdf
New ton 3.pdf
 
ច្បាប់ញូតុនទី៣.pptx
ច្បាប់ញូតុនទី៣.pptxច្បាប់ញូតុនទី៣.pptx
ច្បាប់ញូតុនទី៣.pptx
 
Control tipping.pptx
Control tipping.pptxControl tipping.pptx
Control tipping.pptx
 
Bulbous loop.pptx
Bulbous loop.pptxBulbous loop.pptx
Bulbous loop.pptx
 
brush teeth.pptx
brush teeth.pptxbrush teeth.pptx
brush teeth.pptx
 
bracket size.pptx
bracket size.pptxbracket size.pptx
bracket size.pptx
 
arch form KORI copy.pptx
arch form KORI copy.pptxarch form KORI copy.pptx
arch form KORI copy.pptx
 
Bracket size
Bracket sizeBracket size
Bracket size
 
Couple
CoupleCouple
Couple
 
ច្បាប់ញូតុនទី៣
ច្បាប់ញូតុនទី៣ច្បាប់ញូតុនទី៣
ច្បាប់ញូតុនទី៣
 
Game1
Game1Game1
Game1
 
Shoe horn loop
Shoe horn loopShoe horn loop
Shoe horn loop
 
Opus loop
Opus loopOpus loop
Opus loop
 
V bend
V bendV bend
V bend
 
Closing loop
Closing loopClosing loop
Closing loop
 
Maxillary arch form
Maxillary arch formMaxillary arch form
Maxillary arch form
 
Front face analysis
Front face analysisFront face analysis
Front face analysis
 

Recently uploaded

Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
shyamraj55
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Safe Software
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Malak Abu Hammad
 
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
Neo4j
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
Octavian Nadolu
 
Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
Zilliz
 
GraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracyGraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracy
Tomaz Bratanic
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
mikeeftimakis1
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
Safe Software
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
innovationoecd
 
Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
tolgahangng
 
GenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizationsGenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizations
kumardaparthi1024
 
UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5
DianaGray10
 
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial IntelligenceAI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
IndexBug
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc
 
Mariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceXMariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceX
Mariano Tinti
 
Infrastructure Challenges in Scaling RAG with Custom AI models
Infrastructure Challenges in Scaling RAG with Custom AI modelsInfrastructure Challenges in Scaling RAG with Custom AI models
Infrastructure Challenges in Scaling RAG with Custom AI models
Zilliz
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
Quotidiano Piemontese
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
KAMESHS29
 
Mind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AIMind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AI
Kumud Singh
 

Recently uploaded (20)

Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
 
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
 
Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
 
GraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracyGraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracy
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
 
Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
 
GenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizationsGenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizations
 
UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5
 
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial IntelligenceAI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
 
Mariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceXMariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceX
 
Infrastructure Challenges in Scaling RAG with Custom AI models
Infrastructure Challenges in Scaling RAG with Custom AI modelsInfrastructure Challenges in Scaling RAG with Custom AI models
Infrastructure Challenges in Scaling RAG with Custom AI models
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
 
Mind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AIMind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AI
 

6. chapter v

  • 1. Disk File Input and Output
  • 2. • A file can refer to a disk file, a terminal, a printer, or a tape drive. • Stream is data flow you transfer from your program to a file, or vice versa. • buffer is a memory area, which is temporarily used to store data before it is sent to its destination. • Step of file – Opening a File FILE *fopen(char *filename,char *mode); – Closing a File fclose(*pfile); Note: • "w" Open text file for write operations. If the file exists, its current contents are discarded. • "a" Open a text file for append operations. All writes are to the end of the file. • "r" Open a text file for read operations.
  • 3. Writing to a Text File
  • 4. Reading from a Text File
  • 5. #include <stdio.h> #include <string.h> #include <stdlib.h> const int LENGTH = 80; /* Maximum input length */ int main(void) { char mystr[LENGTH]; /* Input string */ int lstr = 0; /* Length of input string */ int mychar = 0; /* Character for output */ FILE *pfile = NULL; /* File pointer */ char *filename = "C:myfile.txt"; printf("nEnter string of less than 80 characters:n"); fgets(mystr, LENGTH, stdin); /* Read in a string */ /* Create a new file we can write */ if(!(pfile = fopen(filename, "w"))) { printf("Error %s for writing. ", filename); exit(1); } lstr = strlen(mystr); for(int i = lstr-1 ; i >= 0 ; i--) fputc(mystr[i], pfile); /* Write string to file */ fclose(pfile); /* Close the file */ /* Open the file for reading */ if(!(pfile = fopen(filename, "r"))) { printf("Error opening %s for reading. Program terminated.", filename); exit(1); } /* Read a character from the file and display it */ while((mychar = fgetc(pfile)) != EOF) putchar(mychar); /* Output character from the file */ putchar('n'); /* Write newline */ fclose(pfile); /* Close the file */ remove(filename); /* Delete the physical file */ return 0; }
  • 6. /* 21L02.c: Reading and writing one character at a time */ #include <stdio.h> enum {SUCCESS, FAIL}; void CharReadWrite(FILE *fin, FILE *fout); main(void) { FILE *fptr1, *fptr2; char filename1[]= "outhaiku.txt"; char filename2[]= "haiku.txt"; int reval = SUCCESS; if ((fptr1 = fopen(filename1, "w")) == NULL){ printf("Cannot open %s.n", filename1); reval = FAIL; } else if ((fptr2 = fopen(filename2, "r")) == NULL){ printf("Cannot open %s.n", filename2); reval = FAIL; } else { CharReadWrite(fptr2, fptr1); fclose(fptr1); fclose(fptr2); } return reval; } /* function definition */ void CharReadWrite(FILE *fin, FILE *fout) { int c; while ((c=fgetc(fin)) != EOF){ fputc(c, fout); /* write to a file */ putchar(c); /* put the character on the screen */ } }
  • 7. /* 21L03.c: Reading and writing one line at a time */ #include <stdio.h> enum {SUCCESS, FAIL, MAX_LEN = 81}; void LineReadWrite(FILE *fin, FILE *fout); main(void) { FILE *fptr1, *fptr2; char filename1[]= "outhaiku.txt"; char filename2[]= "haiku.txt"; int reval = SUCCESS; if ((fptr1 = fopen(filename1, "w")) == NULL){ printf("Cannot open %s for writing.n", filename1); reval = FAIL; } else if ((fptr2 = fopen(filename2, "r")) == NULL){ printf("Cannot open %s for reading.n", filename2); reval = FAIL; } else { LineReadWrite(fptr2, fptr1); fclose(fptr1); fclose(fptr2); } return reval; } /* function definition */ void LineReadWrite(FILE *fin, FILE *fout) { char buff[MAX_LEN]; while (fgets(buff, MAX_LEN, fin) != NULL){ fputs(buff, fout); printf("%s", buff); } }