Disclaimer: This presentation is prepared by trainees of
baabtra as a part of mentoring program. This is not official
docu...
Week Target Achieved
1 30 20
2 30 21
3 30
Typing Speed
File handling in c
Yasirmusthafapp
yasirmusthafapp@gmail.com
www.facebook.com/yasirmusthafa
twitter.com/yasirmusthafapp
in...
Console application
• Traditional I/O system
• Text based interface(black windows screen)
• User executes the program and ...
Draw back of traditional I/O
• Data is temporary
• Not available during re-execution
Introduction to file handling
• Data is stored onto the disk
• Retrieve whenever required
• Output –stored on to the disk
File
• Sequence of bytes where group of related
data is stored
• Collection of bytes interpreted as
Single character
Singl...
File (conti)
• Last byte of file contains end of file character
(EOF)
• Can be used to check to know the end
• Structure p...
File handling
• Fopen() -create or open a file
• Fclose() -close a file
• Getc() -reads a character from a file
• Putc() -...
Two kindes of files
• Text(ASCII)
• Binary(non ASCII)
-image,audio,vedio,executable,etc
Fopen()
• To create a new file or to open an existing file
Syntax
Fopen(filename,mode);
Eg:-fp=fopen(“data.txt”,”r”);
Retu...
modes
1. r –opens file for reading
2. w-creates a file writing , over writes on previous
content(delete)
3. a-opens a file...
Fclose()
• Close an opened file
Syntax
Fclose(pointer_name);
Eg:-fclose(fp);
• Return zero on success
• Return EOF on error
Writing to a file&Reading data from a
file
Fprintf() & fscanf()
• Just like printf() & scanf()
Eg:-fprintf(fp,”babtra”);
E...
Example
#include<stdio.h>
void main()
{
char name[50];
FILE *fp;
fp=fopen("yasir.txt","r+");
fprintf(fp,"hello_yasirn");
r...
If this presentation helped you, please visit our
page facebook.com/baabtra and like it.
Thanks in advance.
www.baabtra.co...
Contact Us
Emarald Mall (Big Bazar Building)
Mavoor Road, Kozhikode,
Kerala, India.
Ph: + 91 – 495 40 25 550
NC Complex, N...
File handling in c
Upcoming SlideShare
Loading in …5
×

File handling in c

757 views

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
757
On SlideShare
0
From Embeds
0
Number of Embeds
4
Actions
Shares
0
Downloads
24
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

File handling in c

  1. 1. Disclaimer: This presentation is prepared by trainees of baabtra as a part of mentoring program. This is not official document of baabtra –Mentoring Partner Baabtra-Mentoring Partner is the mentoring division of baabte System Technologies Pvt . Ltd
  2. 2. Week Target Achieved 1 30 20 2 30 21 3 30 Typing Speed
  3. 3. File handling in c Yasirmusthafapp yasirmusthafapp@gmail.com www.facebook.com/yasirmusthafa twitter.com/yasirmusthafapp in.linkedin.com/in/yasirmusthafapp 8891396749
  4. 4. Console application • Traditional I/O system • Text based interface(black windows screen) • User executes the program and output displayed on the screen
  5. 5. Draw back of traditional I/O • Data is temporary • Not available during re-execution
  6. 6. Introduction to file handling • Data is stored onto the disk • Retrieve whenever required • Output –stored on to the disk
  7. 7. File • Sequence of bytes where group of related data is stored • Collection of bytes interpreted as Single character Single word Single line Complete structure
  8. 8. File (conti) • Last byte of file contains end of file character (EOF) • Can be used to check to know the end • Structure pointer of file type –to declare a file Eg:-FILE *fp Fp=fopen();
  9. 9. File handling • Fopen() -create or open a file • Fclose() -close a file • Getc() -reads a character from a file • Putc() -writes a character to a file • Fscanf() -reads a set of data from a file • Fprintf() -writes a set of data to a file • Getw() -reads an integer from a file • Putw() -writes an integer to a file • Fseek() -set the position to desire point • Ftell() -gives current position in the file • Rewind() -set the position to the begning
  10. 10. Two kindes of files • Text(ASCII) • Binary(non ASCII) -image,audio,vedio,executable,etc
  11. 11. Fopen() • To create a new file or to open an existing file Syntax Fopen(filename,mode); Eg:-fp=fopen(“data.txt”,”r”); Return NULL-unable to open
  12. 12. modes 1. r –opens file for reading 2. w-creates a file writing , over writes on previous content(delete) 3. a-opens a file for appending-writing on the end of file • “+” character-read & write • Can add a “b” character(non asci) –file is a binary -”rb” , ”wb” or “ab”
  13. 13. Fclose() • Close an opened file Syntax Fclose(pointer_name); Eg:-fclose(fp); • Return zero on success • Return EOF on error
  14. 14. Writing to a file&Reading data from a file Fprintf() & fscanf() • Just like printf() & scanf() Eg:-fprintf(fp,”babtra”); Eg:-fscanf(fp,”%s”,variable); • Except-first argument:file pointer Fputs()&fgets() Fputc()&fgetc()
  15. 15. Example #include<stdio.h> void main() { char name[50]; FILE *fp; fp=fopen("yasir.txt","r+"); fprintf(fp,"hello_yasirn"); rewind(fp); fscanf(fp,"%s",name); printf("%s",name); fclose(fp); }
  16. 16. If this presentation helped you, please visit our page facebook.com/baabtra and like it. Thanks in advance. www.baabtra.com | www.massbaab.com |www.baabte.com
  17. 17. Contact Us Emarald Mall (Big Bazar Building) Mavoor Road, Kozhikode, Kerala, India. Ph: + 91 – 495 40 25 550 NC Complex, Near Bus Stand Mukkam, Kozhikode, Kerala, India. Ph: + 91 – 495 40 25 550 Start up Village Eranakulam, Kerala, India. Email: info@baabtra.com NIT-TBI, NIT Campus, Kozhikode, Kerala, India.

×