Top Banner
13

File oparation in c

Nov 07, 2014

Download

Education

File oparation in c
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: File oparation in c
Page 2: File oparation in c

Disclaimer: This presentation is prepared by trainees of baabtra as a part of mentoring program. This is not official document of baabtra –Mentoring PartnerBaabtra-Mentoring Partner is the mentoring division of baabte System Technologies Pvt . Ltd

Page 3: File oparation in c

Muhammed [email protected] breezeShafi breezein.linkedin.com/in/

profilename9961073949

Typing Speed: 20

Page 4: File oparation in c

TOPIC

File operations in C

Page 5: File oparation in c

File operations

We frequently use files for storing information which can be processed by our programs. In order to store information permanently and retrieve it we need to use files.

Files are not only used for data. Our programare also stored in files.

Page 6: File oparation in c

• In C we use FILE * to represent a pointer to a file.

• fopen is used to open a file. It returns the special

• value NULL to indicate that it couldn't open the file.

Page 7: File oparation in c

Modes for opening files The second argument of fopen is the mode in which we open the file. There are three• "r" opens a file for reading• "w" creates a file for writing - and writes over all previous contents (deletes the file so be careful!)• "a" opens a file for appending - writing on the end of the file• “rb” read binary file (raw bytes)• “wb” write binary fil

Page 8: File oparation in c

Writing to a file using fprintf( )

fprintf( ) works just like printf and sprintfexcept that its first argument is a file pointer.

Page 9: File oparation in c

Reading Data Using fscanf( )

We also read data from a file using fscanf( ).

Page 10: File oparation in c

Closing a file

We can close a file simply using fclose( ) and the file pointer.

Page 11: File oparation in c

Example of File operations

Page 12: File oparation in c

THE END

Create by

Shafi

Page 13: File oparation in c

Contact Us

Emarald Mall (Big Bazar Building)Mavoor Road, Kozhikode,Kerala, India.Ph: + 91 – 495 40 25 550

NC Complex, Near Bus StandMukkam, Kozhikode,Kerala, India.Ph: + 91 – 495 40 25 550

Start up VillageEranakulam,Kerala, India.

Email: [email protected]