Darshan Institute of Engineering & Technology for Diploma Studies Unit 6
|
|
- Ernest Boone
- 5 years ago
- Views:
Transcription
1 1 File Management શ છ? Real life મ, આપણ data ન parmenetly store કરવ મ ગ એ છ એ અન ત થ ત data ન retrive અન reuse કર શક એ છ એ. File એ bytes ન સમ હ છ જ secondary storage મ stored હ ય છ જ મ ક hard disk, pen drive અન tape. file ન બ પ રક ર પ ર ગ ર મ મર text file અન binary file સ થ ક મ કર Text file ન human વ ચ શક છ અન ત english અક ષ રર મ હ ય Binary file ન human વ ચ શકત નથ અન ત processed character અન symbols ASCII મ હ ય 2 File Opening Modes સમજ વ. File ન open અમ ક purpose મ ટ કરવ મ આવ છ જ વ ક read file, create new file, append file, read and write file વગ ર. આપણ જ ય ર ક ઈ પણ file open કર એ છ એ ત ય ર ત સમય open mode મ હ ય જ file open કર એ છ એ ત ત ન mode ન આધ ર ત ન પર limited operation કર શક ય ઉ.દ. fp = fopen( demo.txt, r ); //અહહય file ફક ત read mode મ open કર લ Text file મ ટ C મ 6 પ રક ર ન opening modes 1) r ફક ત reading મ ટ 2) w Writing મ ટ (જ file exist હ ય ત ત ન over-write કરશ ) 3) a Append મ ટ (જ file exist ન હ ય ત નવ file create કરશ ) 4) r+ File મ reading અન writing શર આત થ start કરશ. 5) w+ File મ reading and writing થશ પર ત file overwrite થશ. 6) a+ File reading and writing મ ટ open કરશ અન file ન અ ત append કરશ. આજ પ રક ર ન modes binary file મ ટ પણ ઉપય ગ કર શક ય છ ફક ત b ન add કર ન.જ મ ક rb, wb, ab, r+b, w+b, a+b. 3 Write a C program to display file on screen. #include <stdio.h> void main() FILE *fp; char ch ; // fp એ file pointer fp = fopen( prog_read.c, r ); // Prog.c file ન ફક ત read mode મ open કર લ 1
2 ch = getc(fp) ; while (ch!= EOF) putchar(ch); ch = getc (fp); fclose(fp); // EOF = End of File. file ન અ ત સ ધ read કરશ. // એક character file મ થ Reads કરશ અન position ન increment કરશ. // file ન close કરવ થ file ન બ જ access કર શક 4 Write a C program to copy a file. #include <stdio.h> void main() FILE *p,*q; char ch; p = fopen( Prog_read.txt,"r"); q = fopen( Prog_write.txt,"w"); ch = getc(p); while(ch!= EOF) putc(ch, q); ch = getc(p); printf("file is copied successfully. "); fclose(p); fclose(q); return 0; 5 File handing functions ઉદ હરણ સ થ સમજ વ. File મ operation કરવ મ ટ C મ ઘણ બધ function આ function ન file handling function કહ દર ક function ન ઉપય ગ ખ સ purpose મ ટ થ ય fopen() (Open file) File ન open કરવ મ ટ fopen function ન ઉપય ગ થ ય File ન open કરવ મ ટ file ન ન મ અથવ file ન પ થ આપવ પડ File પર ક વ પ રક ર ન operation થ ય છ ત file opening mode પર આધ હરત જ file successfully open થ ય ત ત file મ pointer return કરશ નહ તર null return કરશ. 2
3 fp = fopen( Prog.c, r ); // File ન ન મ prog.c અન ત ફક ત read mode મ open કર લ. fclose() (Close file) જ ય ર operation પ ર થ ય ત ય ર file ન બ ધ કર દ વ મ આવ fclose function file ન close કરવ મ ટ ઉપય ગ file ન close કરવ મ ટ fclose() function મ file pointer ન pass કરવ મ આવ જ file successfullly closed થ ય ત return 0 નહ તર EOF return કર fclose (fp); fprintf() (Write formatted output to file) fprint() function ન ઉપય ગ file ન information ન ચ ક કસ format મ પ રપ રન ટ કરવ મ ટ થ ય ત print() function જ વ જ ક મ કર ત મ difference એ છ ક fprintf() function મ file pointer pass કરવ મ આવ જ error occurs થ ય ત output તર ક negative number અથવ character number મળ ત output મ characters return કર છ અન જ error હ ય ત negative number કર fprintf(fp, Sum = %d, sum); fscanf() (Read formatted data from file) fscanf() function આપ લ file મ થ information ન read કર ત scanf() function જ વ જ ક મ કર ત મ difference એ છ ક file pointer ન function મ pass કરવ મ આવ જ reading successfully થ ય ત જ ટલ variable ન value assign થઇ હ ય ત return કર છ અન જ error હ ય ત EOF return કર fscanf(fp, %d, &sum); fseek() (Reposition file position indicator) File સ થ ન position indicator ન નવ position પર set કર Original position મ offset ન value add કર ન. fseekf() function ન ઉપય ગ કર ન આગળ જઈ શક પર ત file ન starting પહ લ ન જઈ શક. file સ થ જ EOF flag હ ય ત fseek() દ વ ર clear થ ય 3
4 fseek() function મ ત રણ argument પ સ કરવ પડ file pointer, ક ટલ character અન ક ય location થ. fseek() function 0 return કર ત successed નહ તર failure. Origin value ન ચ ન મ થ ક ઈ પણ એક હ વ જ ઈએ. Name Explanation SEEK_SET SEEK_CUR SEEK_END Seek from the start of the file Seek from the current location Seek from the end of the file fseek(fp, 9, SEEK_SET); //File ન position indicator ન શર આત થ 9 th position પર move કર ftell() (Get current position in file) File મ position indicator ન current value ન return કર Binary stream મ ટ ftell() function starting થ ક ટલ bytes છ ત return કર position = ftell (fp); rewind() (Set position indicator to the beginning) File ન position indicator ન file ન શર આત મ set કર rewind() અન fseek (fp, 0, seek_set) બ ન same જ જ file ન update કરવ મ ટ open કર લ હ ય ત મ rewind() ન call કરવ થ reading અન writing ન વચ ચ switch કર શક ય rewind (fp); getc() (Get character from file) file મ થ next character return કર છ અન જ file complete થઇ હ ય ત EOF return કર Character read થય પછ getc() function file મ character ન એક position increament કર getc() અન getchar() same fgetc () અન getc() એક જ ch = getc(fp); 4
5 putc() (Write character to file) putc() function ન ઉપય ગ file મ character ન write કરવ મ ટ થ ય છ અન position indicator ન increament કર Character print થય પછ putc() function file મ એક character ન position increament કર જ ક ઈ error ન હ ય ત same character ન return કર છ અન જ error હ ય ત EOF return કર putc() અન putchar() બ ન same જ fputc() અન putc() બન એક જ putc(ch, fp); getw() (Get integer from file) getw() function file મ થ next integer ન return કર છ અન જ error હ ય ત EOF return કર i = getw (fp); putw() (Write integer to file) putw() function ન ઉપય ગ file મ integer ન write કરવ મ ટ થ ય છ અન position indicator ન increament કર છ જ success થ ય ત same integer return કર છ નહ તર EOF file return કર putw (I, fp); feof() Feof() function ન ઉપય ગ, ફ ઈલ ન end ન check કરવ મ ટ થ ય ફ ઈલમ થ વ ચત વખત જય ર અ ત લ વ છ ત ય ર આ function true થ ય છ અન વ લ ય 1 return કર છ નહહ ત 0 return કર feof (fp); 6 Write a program to count the number of lines, number of tabs, characters and words in a given file. #include <stdio.h> void main() 5
6 FILE *fp; int lines=0, tabs=0, characters=0, words = 0; char ch, filename[100] ; printf( Enter your file name: ); gets( filename ); // You can also use scanf( %s,filename); fp = fopen( filename, r ); if ( fp == NULL ) // File is not opened successfully then it returns NULL. printf( Cannot open %s for reading \n, filename ); exit(1); /* terminate program */ ch = getc(fp ) ; while ( ch!= EOF ) if ( ch == \n ) lines++ ; else if ( ch == \t ) tabs ++ ; else if ( ch == ) words ++ ; else characters++; c = getc ( fp ); fclose( fp ); printf( Lines=%d Tabs=%d Words=%d Characters=%d, lines, tabs, words, characters); 7 Input / Output ફ કશન સમજ વ. Unformatted input output functions : scanf( ) scanf() function બધ data-type ન read કર છ. scanf() string વચ ચ ન white space ન read કર શકત નથ. printf( ) scanf() મ એક કરત વધ ર format specifier દ વ ર એક કરત વધ ર data ન read કર શક ય scanf( %d%d, &a, &b); ત ન ઉપય ગ બધ જ પ રક ર ન data અન message display કરવ મ ટ થ ય printf() મ એક કરત વધ ર format specifier દ વ ર એક કરત વધ ર data ન display કર શક ય 6
7 printf( a=%d, b=%d, a, b); Unformatted input output functions : gets() ત white space વ ળ એક string ન read કરવ મ ટ ઉપય ગ થ ય ત enter key અથવ end of line વડ ટપ રમ ન ટ થ ય char str[10]; gets (str) getchar(), getche( ), getch( ) ત એક સમય એક જ character ન read કરવ મ ટ વપર ય getchar() function મ ઇનપ ટ ન ટપ રમ ન ટ કરવ મ ટ enter key જર ર છ જય ર getch() અન getche() મ જર ર પડત નથ. getch() function ઇનપ ટ character ન display નથ કરત જય ર getchar() અન getche() function ઇનપ ટ character ન screen પર diplay કર char ch; ch = getchar(); ch = getche(); ch = getch(); puts() ત string ન display કરવ ઉપય ગ char str[]= Hello ; puts (str ); putchar() ત એક જ character display કરવ મ ટ ઉપય ગ putchar(ch); 8 કમ ન ડ લ ઈન આર મ ન ટ ઉદ હરણ સ થ સમજ વ. કમ ન ડ લ ઈન ઓપ ર ટ ગ સ સ ટમ જ વ ક DOS અથવ Linux મ કમ ન ડ લ ઈન આર મ ન ટ પ ર ગ ર મ ન ન મ પછ આપવ મ આવ 7
8 અત ય ર સ ધ આપણ main() function મ ક ઈ આર મ ન ટ pass કરત ન હત. main() મ બ આર મ ન ટ pass કર શક ય છ : 1) First આર મ ન ટ ક ટલ કમ ન ડ લ ઈન આર મ ન ટ છ ત દશ વ 2) Second આર મ ન ટ કમ ન ડ લ ઈન આર મ ન ટ ન list pass કરવ મ આવ Syntax: int main(int argc, char *argv[]) argc એ ક ટલ આર મ ન ટ છ ત દશ વ છ અન argv[] pointer array છ જ દર ક આર મ ન ટ ન point કર ન ચ આપ લ ઉદ હરણ મ જ ક ઈ આર મ ન ટ કમ ન ડ લ ઈન દ વ ર pass કરવ મ આવ ત એ મ જબ output મ Print થશ. #include <stdio.h> int main( int argc, char *argv[] ) if( argc == 2 ) printf("the argument supplied is %s\n", argv[1]); else if( argc > 2 ) printf("too many arguments supplied.\n"); else printf("one argument expected.\n"); અહહય argv[0] program ન ન મ સ ટ ર થ ય છ અન argv[1] એ first કમ ન ડ લ ઈન આર મ ન ટ ન point કર છ અન *argv[n] last આર મ ન ટ થશ. જ ક ઈ આર મ ન ટ pass કરવ મ ન આવ ત argc one થશ, જ એક આર મ ન ટ pass કરવ મ આવ ત argc ન value 2 થશ. કમ ન ડ લ ઈન આર મ ન ટ ન સ પ સ દ વ ર જ દ કરવ મ આવ છ પર ત જ આર મ ન ટ મ જ સ પ સ હ ય ત ત આર મ ન ટ ન ડબલ ક વ ટ ( ) અથવ પ રસ ગલ ક વ ટ ) ( ન અ દર ર ખવ મ આવ છ. $./a.out testing1 testing2 Too many arguments supplied. 8
Darshan Institute of Engineering & Technology for Diploma Studies Unit 6
1. What is File management? In real life, we want to store data permanently so that later on we can retrieve it and reuse it. A file is a collection of bytes stored on a secondary storage device like hard
More informationUnit 6 Files. putchar(ch); ch = getc (fp); //Reads single character from file and advances position to next character
1. What is File management? In real life, we want to store data permanently so that later on we can retrieve it and reuse it. A file is a collection of bytes stored on a secondary storage device like hard
More informationGUJARAT TECHNOLOGICAL UNIVERSITY DIPLOMA ENGINEERING SEMESTER 2(C2D) EXAMINATION SUMMER
Seat No.: Enrolment No. GUJARAT TECHNOLOGICAL UNIVERSITY DIPLOMA ENGINEERING SEMESTER 2(C2D) EXAMINATION SUMMER - 2018 Subject Code: C320702 Date: 21-May-2018 Subject Name: ADVANCED COMPUTER PROGRAMMING
More informationGUJARAT TECHNOLOGICAL UNIVERSITY Diploma Engineering Semester VI Examination Dec
Seat No.: Enrolment No. GUJRT TECHNOLOGICL UNIERSITY Diploma Engineering Semester I Examination Dec. - 2011 Subject code: 3602 Date: /12/2011 Subject Name: Database Programming with B.Net Time: 02.30 pm
More informationa,f[u:5f[8df\ a,f[u S[JL ZLT[ AGFJXF[m
zl DCF,äDL lh(,f lx16 VG[ TF,LD EJG4 VDNFJFN U FdI a,f[u:5f[8df\ a,f[u S[JL ZLT[ AGFJXF[m RF{CF6 EZTS]DFZ V[,P D]bIlX1S4 (HTAT) U]\ Z 5 FYlDS XF/F4 TFPW\W]SF4 lhpvdnfjfn DFU"NX"SzL o G}TGA[G ZFJ, 5 FRFI"zL4
More informationવષ ૨૦૧૮ દર ય ન સ ધ થન ર હ ર ત ન ક ય મ
જર ત હ ર સ વ આય ગ વષ ૨૦૧૮ દર ય ન સ ધ થન ર હ ર ત ન ક ય મ જર ત હ ર સ વ આય ગ ર વ વધ જ ય ઓ મ ટ સ ધ ભરત / પધ મક પર ર ભરત મ ટ વષ ૨૦૧૮ દર મય ન સ ધ કરવ ન હ ર ત અ વય ચત ક ય મ ન ચ જબ છ. વ મ હત મ ટ ઉમ દવ ર ન આય ગન
More informationGUJARAT TECHNOLOGICAL UNIVERSITY Diploma Engineering - SEMESTER VI EXAMINATION SUMMER 2013
Seat No.: Enrolment No. GUJRT TECHNOLOGICL UNIVERSITY Diploma Engineering - SEMESTER VI EXMINTION SUMMER 2013 Subject Code: 361901 Date: 09/05/2013 Subject Name: Computer ided Design and Computer ided
More informationGUJARAT TECHNOLOGICAL UNIVERSITY Diploma Semester V th Examination December
Seat No.: Enrolment No. GUJRT TECHNOLOGICL UNIVERSITY Diploma Semester V th Examination December - 2010 Date: 28 /12 /2010 Subject code: 3503 Subject Name: Java Programming Instructions: 1. ttempt all
More informationGujarati Style Guide. Published: December, Microsoft Gujarati Style Guide
Gujarati Style Guide Published: December, 2017 Microsoft Gujarati Style Guide Table of Contents 1 About this style guide... 4 1.1 Recommended style reference... 4 2 Microsoft voice... 5 2.1 Choices that
More informationC Programming Language
C Programming Language File Input/Output Dr. Manar Mohaisen Office: F208 Email: manar.subhi@kut.ac.kr Department of EECE Review of the Precedent Lecture Arrays and Pointers Class Objectives What is a File?
More informationVedant Public School Isanpur, Ahmedabad.
Class- 1 st Vedant Public School Isanpur, Ahmedabad. FA-4 Paper Style English Grammar (L- 4, 5, 6) Q.1 MCQs (10) Q.1 Blanks with in, on, under. (05) Q.2 Answer the questions. (04) Q.3 Fill in the blanks
More informationભ બ ત ક લ ક મ ર ટયન યચન ૧૬૪૨ ભ બ ર ઇઝ સ કર કય શત. ત છ ૧૬૯૦ભ ર ફન ઝ એલ મ ત ર ફન વમ ક જ વયલ, ફ દફ ક, ગ ણ ક ય, બ ગ ક ય તથ લ ગભ ન ગણતય કય ળક.
Abacus : (અફ કવ) ગણતય ભ ટ ન જ ણ ત પ રથભ મ ત ર છ. ભ બ ત ક લ ક મ ર ટયન યચન ૧૬૪૨ ભ બ ર ઇઝ સ કર કય શત. ત છ ૧૬૯૦ભ ર ફન ઝ એલ મ ત ર ફન વમ ક જ વયલ, ફ દફ ક, ગ ણ ક ય, બ ગ ક ય તથ લ ગભ ન ગણતય કય ળક. ૧૮૨૨ભ ચ લ કવગ
More informationMode Meaning r Opens the file for reading. If the file doesn't exist, fopen() returns NULL.
Files Files enable permanent storage of information C performs all input and output, including disk files, by means of streams Stream oriented data files are divided into two categories Formatted data
More informationGUJARAT TECHNOLOGICAL UNIVERSITY Diploma Engineering - SEMESTER III EXAMINATION SUMMER 2014
Seat No.: Enrolment No. GUJRT TECHNOLOGICL UNIVERSITY Diploma Engineering - SEMESTER III EXMINTION SUMMER 2014 Subject Code: 3309 Date: 13-06-2014 Subject Name: Basic Electronics Time: 10:30 am - 01:00
More informationSTYLE AND CONVENTIONS GUIDE FOR COMPUTER TRANSLATIONS INTO GUJARATI
STYLE AND CONVENTIONS GUIDE FOR COMPUTER TRANSLATIONS INTO GUJARATI S W E TA K O T H A R I Publisher: FUEL Project India Tel: Web Site: https://fedorahosted.org/fuel Mailing List: fuel-discuss@lists.fedorahosted.org
More informationIt is an entirely new way of typing and hence please go through the instructions to experience the best usability.
Panini Keypad allows you to write in all languages of India on the phone, fast and easily without the need of printed characters on the keypad. It is based on a patented invention of statistical predictive
More informationટ ડર ન ટ સ ટ ડર થ ૨-૦૦ સ ધ D.D. રજ ટ ર ર, સ ર ટ ર ય નવ સર ટ ન રહ શ. સ ર ટ ર ય નવ સર ટ ર જક ટ અબ ધત અ ધક ર ક લસ ચવ
સ ર ટ ર ય નવ સર ટ ર જક ટ ટ ડર ન ટ સ મ ય ફ ક ચરર તથ અ ધ ત વક ર ત ઓ પ સ થ સ લબ ધ કવરમ ન ચ દશ ર વ લક ય ટરઅન આન સ ગ ક સ ધન ન ભ વ મ ગ વવ મ આવ છ. ક ટરઅન આ સ ગ ક સ ધન ન ર ઇટ ક કટ મ ટ ટ ડર ક ર ટ ડર ફ મર વગત સ
More informationGUJARAT TECHNOLOGICAL UNIVERSITY Diploma Semester V th Examination December
Seat No.: Enrolment No. GUJRT TECHNOLOGICL UNIERSITY Diploma Semester th Examination December - 2010 Subject code: 3504 Subject Name: Computer Networking Date: 29 /12 /2010 Time: 02.30 pm 05.00 pm Total
More informationFile Handling. Reference:
File Handling Reference: http://www.tutorialspoint.com/c_standard_library/ Array argument return int * getrandom( ) static int r[10]; int i; /* set the seed */ srand( (unsigned)time( NULL ) ); for ( i
More informationUNIT IV-2. The I/O library functions can be classified into two broad categories:
UNIT IV-2 6.0 INTRODUCTION Reading, processing and writing of data are the three essential functions of a computer program. Most programs take some data as input and display the processed data, often known
More informationFile I/O. Arash Rafiey. November 7, 2017
November 7, 2017 Files File is a place on disk where a group of related data is stored. Files File is a place on disk where a group of related data is stored. C provides various functions to handle files
More information7/21/ FILE INPUT / OUTPUT. Dong-Chul Kim BioMeCIS UTA
7/21/2014 1 FILE INPUT / OUTPUT Dong-Chul Kim BioMeCIS CSE @ UTA What s a file? A named section of storage, usually on a disk In C, a file is a continuous sequence of bytes Examples for the demand of a
More informationComputer Programming Unit v
READING AND WRITING CHARACTERS We can read and write a character on screen using printf() and scanf() function but this is not applicable in all situations. In C programming language some function are
More informationOrganization of a file
File Handling 1 Storage seen so far All variables stored in memory Problem: the contents of memory are wiped out when the computer is powered off Example: Consider keeping students records 100 students
More informationFundamentals of Programming. Lecture 10 Hamed Rasifard
Fundamentals of Programming Lecture 10 Hamed Rasifard 1 Outline File Input/Output 2 Streams and Files The C I/O system supplies a consistent interface to the programmer independent of the actual device
More information2009 S2 COMP File Operations
2009 S2 COMP1921 9. File Operations Oliver Diessel odiessel@cse.unsw.edu.au Last updated: 16:00 22 Sep 2009 9. File Operations Topics to be covered: Streams Text file operations Binary file operations
More informationFile IO and command line input CSE 2451
File IO and command line input CSE 2451 File functions Open/Close files fopen() open a stream for a file fclose() closes a stream One character at a time: fgetc() similar to getchar() fputc() similar to
More informationInput / Output Functions
CSE 2421: Systems I Low-Level Programming and Computer Organization Input / Output Functions Presentation G Read/Study: Reek Chapter 15 Gojko Babić 10-03-2018 Input and Output Functions The stdio.h contain
More informationCE Lecture 11
Izmir Institute of Technology CE - 104 Lecture 11 References: - C: A software Engineering Approach 1 In this course you will learn Input and Output Sorting Values 2 Input and Output Opening and Closing
More informationENG120. Misc. Topics
ENG120 Misc. Topics Topics Files in C Using Command-Line Arguments Typecasting Working with Multiple source files Conditional Operator 2 Files and Streams C views each file as a sequence of bytes File
More informationSystem Software Experiment 1 Lecture 7
System Software Experiment 1 Lecture 7 spring 2018 Jinkyu Jeong ( jinkyu@skku.edu) Computer Systems Laboratory Sungyunkwan University http://csl.skku.edu SSE3032: System Software Experiment 1, Spring 2018
More informationComputer System and programming in C
File Handling in C What is a File? A file is a collection of related data that a computers treats as a single unit. Computers store files to secondary storage so that the contents of files remain intact
More informationUNIX Shell. The shell sits between you and the operating system, acting as a command interpreter
Shell Programming Linux Commands UNIX Shell The shell sits between you and the operating system, acting as a command interpreter The user interacts with the kernel through the shell. You can write text
More informationCSI 402 Systems Programming LECTURE 4 FILES AND FILE OPERATIONS
CSI 402 Systems Programming LECTURE 4 FILES AND FILE OPERATIONS A mini Quiz 2 Consider the following struct definition struct name{ int a; float b; }; Then somewhere in main() struct name *ptr,p; ptr=&p;
More informationComputer programming
Computer programming "He who loves practice without theory is like the sailor who boards ship without a ruder and compass and never knows where he may cast." Leonardo da Vinci T.U. Cluj-Napoca - Computer
More informationEM108 Software Development for Engineers
EE108 Section 4 Files page 1 of 14 EM108 Software Development for Engineers Section 4 - Files 1) Introduction 2) Operations with Files 3) Opening Files 4) Input/Output Operations 5) Other Operations 6)
More information25.2 Opening and Closing a File
Lecture 32 p.1 Faculty of Computer Science, Dalhousie University CSCI 2132 Software Development Lecture 32: Dynamically Allocated Arrays 26-Nov-2018 Location: Chemistry 125 Time: 12:35 13:25 Instructor:
More informationIntroduction to file management
1 Introduction to file management Some application require input to be taken from a file and output is required to be stored in a file. The C language provides the facility of file input-output operations.
More informationGujarati Character Recognition:Survey
Gujarati Character Recognition:Survey Ms. Honey Patel Computer Engineering CHARUSAT,Changa Anand, India Ms. Rinku Bathani Computer Engineering CHARUSAT,Changa Anand, India Abstract Today most of people
More informationChapter 12. Files (reference: Deitel s chap 11) chap8
Chapter 12 Files (reference: Deitel s chap 11) 20061025 chap8 Introduction of File Data files Can be created, updated, and processed by C programs Are used for permanent storage of large amounts of data
More informationUNIT-V CONSOLE I/O. This section examines in detail the console I/O functions.
UNIT-V Unit-5 File Streams Formatted I/O Preprocessor Directives Printf Scanf A file represents a sequence of bytes on the disk where a group of related data is stored. File is created for permanent storage
More informationPreprocessing directives are lines in your program that start with `#'. The `#' is followed by an identifier that is the directive name.
Unit-III Preprocessor: The C preprocessor is a macro processor that is used automatically by the C compiler to transform your program before actual compilation. It is called a macro processor because it
More informationCh 11. C File Processing (review)
Ch 11 C File Processing (review) OBJECTIVES To create, read, write and update files. Sequential access file processing. Data Hierarchy Data Hierarchy: Bit smallest data item Value of 0 or 1 Byte 8 bits
More informationInput/Output: Advanced Concepts
Input/Output: Advanced Concepts CSE 130: Introduction to Programming in C Stony Brook University Related reading: Kelley/Pohl 1.9, 11.1 11.7 Output Formatting Review Recall that printf() employs a control
More informationCSI 402 Lecture 2 (More on Files) 2 1 / 20
CSI 402 Lecture 2 (More on Files) 2 1 / 20 Files A Quick Review Type for file variables: FILE * File operations use functions from stdio.h. Functions fopen and fclose for opening and closing files. Functions
More informationCSI 402 Lecture 2 Working with Files (Text and Binary)
CSI 402 Lecture 2 Working with Files (Text and Binary) 1 / 30 AQuickReviewofStandardI/O Recall that #include allows use of printf and scanf functions Example: int i; scanf("%d", &i); printf("value
More informationContent. Input Output Devices File access Function of File I/O Redirection Command-line arguments
File I/O Content Input Output Devices File access Function of File I/O Redirection Command-line arguments UNIX and C language C is a general-purpose, high-level language that was originally developed by
More informationPROGRAMMAZIONE I A.A. 2017/2018
PROGRAMMAZIONE I A.A. 2017/2018 INPUT/OUTPUT INPUT AND OUTPUT Programs must be able to write data to files or to physical output devices such as displays or printers, and to read in data from files or
More informationC Programming 1. File Access. Goutam Biswas. Lect 29
C Programming 1 File Access C Programming 2 Standard I/O So far all our I/O operations are read from the standard input (stdin - keyboard) and write to the standard output (stdout - VDU) devices. These
More informationC-Refresher: Session 10 Disk IO
C-Refresher: Session 10 Disk IO Arif Butt Summer 2017 I am Thankful to my student Muhammad Zubair bcsf14m029@pucit.edu.pk for preparation of these slides in accordance with my video lectures at http://www.arifbutt.me/category/c-behind-the-curtain/
More informationC File Processing: One-Page Summary
Chapter 11 C File Processing C File Processing: One-Page Summary #include int main() { int a; FILE *fpin, *fpout; if ( ( fpin = fopen( "input.txt", "r" ) ) == NULL ) printf( "File could not be
More informationProgramming & Data Structure
File Handling Programming & Data Structure CS 11002 Partha Bhowmick http://cse.iitkgp.ac.in/ pb CSE Department IIT Kharagpur Spring 2012-2013 File File Handling File R&W argc & argv (1) A file is a named
More informationCS240: Programming in C
CS240: Programming in C Lecture 13 si 14: Unix interface for working with files. Cristina Nita-Rotaru Lecture 13/Fall 2013 1 Working with Files (I/O) File system: specifies how the information is organized
More informationLANGUAGE OF THE C. C: Part 6. Listing 1 1 #include <stdio.h> 2 3 int main(int argc, char *argv[]) PROGRAMMING
C: Part 6 LANGUAGE OF THE C In part 6 of Steve Goodwins C tutorial we continue our look at file handling and keyboard input File handling Most software will at some time need to read from (or perhaps write
More informationStandard File Pointers
1 Programming in C Standard File Pointers Assigned to console unless redirected Standard input = stdin Used by scan function Can be redirected: cmd < input-file Standard output = stdout Used by printf
More informationChapter 11 File Processing
1 Chapter 11 File Processing Copyright 2007 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 2 Chapter 11 File Processing Outline 11.1 Introduction 11.2 The Data Hierarchy 11.3
More informationDS: CS Computer Sc & Engg: IIT Kharagpur 1. File Access. Goutam Biswas. ect 29
DS: CS 11002 Computer Sc & Engg: IIT Kharagpur 1 File Access DS: CS 11002 Computer Sc & Engg: IIT Kharagpur 2 Standard I/O So far all our I/O operations are read from the standard input (stdin - keyboard)
More informationInput/Output and the Operating Systems
Input/Output and the Operating Systems Fall 2015 Jinkyu Jeong (jinkyu@skku.edu) 1 I/O Functions Formatted I/O printf( ) and scanf( ) fprintf( ) and fscanf( ) sprintf( ) and sscanf( ) int printf(const char*
More informationLecture 8. Dr M Kasim A Jalil. Faculty of Mechanical Engineering UTM (source: Deitel Associates & Pearson)
Lecture 8 Data Files Dr M Kasim A Jalil Faculty of Mechanical Engineering UTM (source: Deitel Associates & Pearson) Objectives In this chapter, you will learn: To be able to create, read, write and update
More informationIntermediate Programming, Spring 2017*
600.120 Intermediate Programming, Spring 2017* Misha Kazhdan *Much of the code in these examples is not commented because it would otherwise not fit on the slides. This is bad coding practice in general
More informationFile Processing. Chih-Wei Tang ( 唐之瑋 ) Department of Communication Engineering National Central University JhongLi, Taiwan
File Processing Chih-Wei Tang ( 唐之瑋 ) Department of Communication Engineering National Central University JhongLi, Taiwan Outline 11.2 The Data Hierarchy 11.3 Files and Streams 11.4 Creating a Sequential
More informationFiles. Programs and data are stored on disk in structures called files Examples. a.out binary file lab1.c - text file term-paper.
File IO part 2 Files Programs and data are stored on disk in structures called files Examples a.out binary file lab1.c - text file term-paper.doc - binary file Overview File Pointer (FILE *) Standard:
More informationChapter 10. File Processing 248 FILE PROCESSING
Chapter 10 FILE PROCESSING LEARNING OBJECTIVES After reading this chapter the reader will be able to understand the need of data file. learn the operations on files. use different data input/output functions
More informationData File and File Handling
Types of Disk Files Data File and File Handling Text streams are associated with text-mode files. Text-mode files consist of a sequence of lines. Each line contains zero or more characters and ends with
More informationC How to Program, 6/e by Pearson Education, Inc. All Rights Reserved.
C How to Program, 6/e Storage of data in variables and arrays is temporary such data is lost when a program terminates. Files are used for permanent retention of data. Computers store files on secondary
More informationSystems Programming. 08. Standard I/O Library. Alexander Holupirek
Systems Programming 08. Standard I/O Library Alexander Holupirek Database and Information Systems Group Department of Computer & Information Science University of Konstanz Summer Term 2008 Last lecture:
More informationBIL 104E Introduction to Scientific and Engineering Computing. Lecture 12
BIL 104E Introduction to Scientific and Engineering Computing Lecture 12 Files v.s. Streams In C, a file can refer to a disk file, a terminal, a printer, or a tape drive. In other words, a file represents
More informationM.CS201 Programming language
Power Engineering School M.CS201 Programming language Lecture 16 Lecturer: Prof. Dr. T.Uranchimeg Agenda Opening a File Errors with open files Writing and Reading File Data Formatted File Input Direct
More informationUNIX System Programming
File I/O 경희대학교컴퓨터공학과 조진성 UNIX System Programming File in UNIX n Unified interface for all I/Os in UNIX ü Regular(normal) files in file system ü Special files for devices terminal, keyboard, mouse, tape,
More information8. Structures, File I/O, Recursion. 18 th October IIT Kanpur
8. Structures, File I/O, Recursion 18 th October IIT Kanpur C Course, Programming club, Fall 2008 1 Basic of Structures Definition: A collection of one or more different variables with the same handle
More informationStandard C Library Functions
Demo lecture slides Although I will not usually give slides for demo lectures, the first two demo lectures involve practice with things which you should really know from G51PRG Since I covered much of
More informationLecture 9: File Processing. Quazi Rahman
60-141 Lecture 9: File Processing Quazi Rahman 1 Outlines Files Data Hierarchy File Operations Types of File Accessing Files 2 FILES Storage of data in variables, arrays or in any other data structures,
More informationLecture6 File Processing
1 Lecture6 File Processing Dr. Serdar ÇELEBİ 2 Introduction The Data Hierarchy Files and Streams Creating a Sequential Access File Reading Data from a Sequential Access File Updating Sequential Access
More informationProgramming Fundamentals
Programming Fundamentals Day 4 1 Session Plan Searching & Sorting Sorting Selection Sort Insertion Sort Bubble Sort Searching Linear Search Binary Search File Handling Functions Copyright 2004, 2 2 Sorting
More informationWeek 9 Lecture 3. Binary Files. Week 9
Lecture 3 Binary Files 1 Reading and Writing Binary Files 2 Binary Files It is possible to write the contents of memory directly to a file. The bits need to be interpreted on input Possible to write out
More informationfopen() fclose() fgetc() fputc() fread() fwrite()
The ability to read data from and write data to files is the primary means of storing persistent data, data that does not disappear when your program stops running. The abstraction of files that C provides
More informationQuick review of previous lecture Ch6 Structure Ch7 I/O. EECS2031 Software Tools. C - Structures, Unions, Enums & Typedef (K&R Ch.
1 Quick review of previous lecture Ch6 Structure Ch7 I/O EECS2031 Software Tools C - Structures, Unions, Enums & Typedef (K&R Ch.6) Structures Basics: Declaration and assignment Structures and functions
More informationC programming basics T3-1 -
C programming basics T3-1 - Outline 1. Introduction 2. Basic concepts 3. Functions 4. Data types 5. Control structures 6. Arrays and pointers 7. File management T3-2 - 3.1: Introduction T3-3 - Review of
More informationFiles and Streams Opening and Closing a File Reading/Writing Text Reading/Writing Raw Data Random Access Files. C File Processing CS 2060
CS 2060 Files and Streams Files are used for long-term storage of data (on a hard drive rather than in memory). Files and Streams Files are used for long-term storage of data (on a hard drive rather than
More informationFile (1A) Young Won Lim 11/25/16
File (1A) Copyright (c) 2010-2016 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version
More informationCSci 4061 Introduction to Operating Systems. Input/Output: High-level
CSci 4061 Introduction to Operating Systems Input/Output: High-level I/O Topics First, cover high-level I/O Next, talk about low-level device I/O I/O not part of the C language! High-level I/O Hide device
More informationIO = Input & Output 2
Input & Output 1 IO = Input & Output 2 Idioms 3 Input and output in C are simple, in theory, because everything is handled by function calls, and you just have to look up the documentation of each function
More informationIntroduction to Programming in C Department of Computer Science and Engineering. Lecture No. #47. File Handling
Introduction to Programming in C Department of Computer Science and Engineering Lecture No. #47 File Handling In this video, we will look at a few basic things about file handling in C. This is a vast
More informationToday s Learning Objectives
Today s Learning Objectives 15-123 Systems Skills in C and Unix We will Review ints and modular arithmetic Learn basic Data types and Formats How Conditionals and loops work How Arrays are defined, accessed,
More informationC Basics And Concepts Input And Output
C Basics And Concepts Input And Output Report Working group scientific computing Department of informatics Faculty of mathematics, informatics and natural sciences University of Hamburg Written by: Marcus
More informationBasic and Practice in Programming Lab 10
Basic and Practice in Programming Lab 10 File (1/4) File management in C language FILE data type (strictly, data structure in C library) Three operational modes Read/Write/Append fopen A library function
More informationAccessing Files in C. Professor Hugh C. Lauer CS-2303, System Programming Concepts
Accessing Files in C Professor Hugh C. Lauer CS-2303, System Programming Concepts (Slides include materials from The C Programming Language, 2 nd edition, by Kernighan and Ritchie, Absolute C++, by Walter
More informationEECS2031. Modifiers. Data Types. Lecture 2 Data types. signed (unsigned) int long int long long int int may be omitted sizeof()
Warning: These notes are not complete, it is a Skelton that will be modified/add-to in the class. If you want to us them for studying, either attend the class or get the completed notes from someone who
More information8. Characters, Strings and Files
REGZ9280: Global Education Short Course - Engineering 8. Characters, Strings and Files Reading: Moffat, Chapter 7, 11 REGZ9280 14s2 8. Characters and Arrays 1 ASCII The ASCII table gives a correspondence
More informationPointers and File Handling
1 Pointers and File Handling From variables to their addresses Pallab Dasgupta Professor, Dept. of Computer Sc & Engg INDIAN INSTITUTE OF TECHNOLOGY KHARAGPUR 2 Basics of Pointers INDIAN INSTITUTE OF TECHNOLOGY
More informationC: How to Program. Week /June/18
C: How to Program Week 17 2007/June/18 1 Chapter 11 File Processing Outline 11.1 Introduction 11.2 The Data Hierarchy 11.3 Files and Streams 11.4 Creating a Sequential Access File 11.5 Reading Data from
More informationFile Handling. 21 July 2009 Programming and Data Structure 1
File Handling 21 July 2009 Programming and Data Structure 1 File handling 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
More informationIntroduction to Computer Programming Lecture 18 Binary Files
Introduction to Computer Programming Lecture 18 Binary Files Assist.Prof.Dr. Nükhet ÖZBEK Ege University Department of Electrical&Electronics Engineering nukhet.ozbek@ege.edu.tr 1 RECALL: Text File Handling
More informationCMPE-013/L. File I/O. File Processing. Gabriel Hugh Elkaim Winter File Processing. Files and Streams. Outline.
CMPE-013/L Outline File Processing File I/O Gabriel Hugh Elkaim Winter 2014 Files and Streams Open and Close Files Read and Write Sequential Files Read and Write Random Access Files Read and Write Random
More informationFile I/O. Preprocessor Macros
Computer Programming File I/O. Preprocessor Macros Marius Minea marius@cs.upt.ro 4 December 2017 Files and streams A file is a data resource on persistent storage (e.g. disk). File contents are typically
More informationCS113: Lecture 7. Topics: The C Preprocessor. I/O, Streams, Files
CS113: Lecture 7 Topics: The C Preprocessor I/O, Streams, Files 1 Remember the name: Pre-processor Most commonly used features: #include, #define. Think of the preprocessor as processing the file so as
More informationAdvanced C Programming Topics
Introductory Medical Device Prototyping Advanced C Programming Topics, http://saliterman.umn.edu/ Department of Biomedical Engineering, University of Minnesota Operations on Bits 1. Recall there are 8
More informationmywbut.com 12 File Input/Output
12 File Input/Output Data Organization File Operations Opening a File Reading from a File Trouble in Opening a File Closing the File Counting Characters, Tabs, Spaces, A File-copy Program Writing to a
More informationCSE2301. Introduction. Streams and Files. File Access Random Numbers Testing and Debugging. In this part, we introduce
Warning: These notes are not complete, it is a Skelton that will be modified/add-to in the class. If you want to us them for studying, either attend the class or get the completed notes from someone who
More informationHIGH LEVEL FILE PROCESSING
HIGH LEVEL FILE PROCESSING 1. Overview The learning objectives of this lab session are: To understand the functions used for file processing at a higher level. o These functions use special structures
More information