Your SlideShare is downloading. ×
0
File handling in c
File handling in c
File handling in c
File handling in c
File handling in c
File handling in c
File handling in c
File handling in c
File handling in c
File handling in c
File handling in c
File handling in c
File handling in c
File handling in c
File handling in c
File handling in c
File handling in c
File handling in c
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

File handling in c

294

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
294
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
18
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  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. Week Target Achieved 1 30 20 2 30 21 3 30 Typing Speed
  3. File handling in c Yasirmusthafapp yasirmusthafapp@gmail.com www.facebook.com/yasirmusthafa twitter.com/yasirmusthafapp in.linkedin.com/in/yasirmusthafapp 8891396749
  4. Console application • Traditional I/O system • Text based interface(black windows screen) • User executes the program and output displayed on the screen
  5. Draw back of traditional I/O • Data is temporary • Not available during re-execution
  6. Introduction to file handling • Data is stored onto the disk • Retrieve whenever required • Output –stored on to the disk
  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. 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. 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. Two kindes of files • Text(ASCII) • Binary(non ASCII) -image,audio,vedio,executable,etc
  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. 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. Fclose() • Close an opened file Syntax Fclose(pointer_name); Eg:-fclose(fp); • Return zero on success • Return EOF on error
  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. 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. 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. 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.

×