SlideShare a Scribd company logo
Unformatted Console I/O Functions 
main( ) 
{ 
printf ( ”Delete all files Y/N” ) ; 
ch = getchar( ) ; 
/* or ch = fgetchar( ) ; */ 
putch ( ch ) ; 
putchar ( ch ) ; 
fputchar ( ch ) ; 
} 
printf ( ”Press any key” ) ; 
getch( ) ; 
printf ( ”Another disk Y/N” ) ; 
ch = getche( ) ; 
same 
char ch ;
Peculiarities 
getch( ) - Doesn’t wait for enter. 
getche( ) - Echoes character. 
getchar( ) - Waits for enter. Macro. 
fgetchar( ) - Waits for enter. Function.
Disk I/O 
High Level / Std Disk I/O Low Level 
Text Binary 
Formatted Unformatted 
char 
int 
fprintf( ) 
float 
fscanf( ) 
string 
char - getc ( ), fgetc( ) 
putc ( ), fputc( ) 
Reads / Writes 
char by char 
int - 
float - No Std. Library Function 
string - fgets( ), fputs( ) 
Reads / Writes 
line by line 
file
Bufferred I/O 
Memory 
)) 
Buffer 
CCHH11PPRR11..CC 
Disk
Displaying File Contents 
# include ”stdio.h” 
char fname[13] ; 
printf ( ”Enter file name” ) ; 
gets ( fname ) ; 
fopen ( ) ; 
main( ) 
{ 
char ch ; 
FILE *fp ; 
fp = fname, ”r” 
while ( 1 ) 
{ 
ch = getc ( ) ; 
if ( ch == EOF ) 
break ; 
printf ( ”%c”, ch ) ; 
} 
fclose ( ) ; 
} 
fp 
fp
typedef 
unsigned long int i, j ; typedef unsigned long int uli ; 
struct employee 
{ ___ 
} ; 
struct employee e1, e2 ; 
struct a 
{ __ 
char *p ; 
} ; 
typedef struct a FILE ; 
uli i, j ; 
struct employee 
{ ___ 
} ; 
typedef struct employee emp ; 
emp e1, e2 ; 
FILE *fp ;
# include ”stdio.h” 
char fname[13] ; 
printf ( ”Enter file name” ) ; 
gets ( fname ) ; 
fopen ( ) ; 
main( ) 
{ 
char ch ; 
FILE *fp ; 
fp = fname, ”r” 
while ( 1 ) 
{ 
ch = getc ( ) ; 
if ( ch == EOF ) 
break ; 
printf ( ”%c”, ch ) ; 
} 
fclose ( ) ; 
} 
fp 
fp 
A Fresh Look 
Buffer 
40 
fp p 
40 
ffpp -->> pp == ffpp -->> pp ++ 11 ;;
Tips 
 fopen( ) - Standard Library Function to open the file. 
 fopen ( fname, ”r” ) ; - Returns NULL if file not found. 
 Every file ends with a char with ascii value 26. 
 EOF is a macro. 
# define EOF -1 
 FILE is a structure defined in stdio.h 
 getc( ) reads char  also shifts pointer to next char.
Copying Files 
char fname[13] , target[13] ; 
printf ( ”Enter source  target file names” ) ; 
gets ( fname ) ; 
gets ( target ) ; 
ft = fopen ( target, ”w” ) ; 
# include ”stdio.h” 
fopen ( ) ; 
main( ) 
{ 
char ch ; 
FILE *fs, *ft ; 
fs = fname, ”r” 
while ( 1 ) 
{ 
ch = getc ( ) ; 
if ( ch == EOF ) 
break ; 
putc ( ) ; 
ch, ft 
} 
fclose ( ) ; 
fs 
fs fclose ( ft ) ; 
}
Copying Files 
char fname[13] , target[13] ; 
printf ( ”Enter source  target file names” ) ; 
gets ( fname ) ; 
gets ( target ) ; 
ft = fopen ( target, ”w” ) ; 
# include ”stdio.h” 
fopen ( ) ; 
main( ) 
{ 
char ch ; 
FILE *fs, *ft ; 
fs = fname, ”r” 
while ( 1 ) 
{ 
ch = getc ( ) ; 
if ( ch == EOF ) 
break ; 
putc ( ) ; 
ch, ft 
} 
fclose ( ) ; 
fs 
fs fclose ( ft ) ; 
}

More Related Content

What's hot

File management
File managementFile management
File management
Mohammed Sikander
 
The bones of a nice Python script
The bones of a nice Python scriptThe bones of a nice Python script
The bones of a nice Python script
saniac
 
Unit 6
Unit 6Unit 6
Unit 6siddr
 
Sysprog17
Sysprog17Sysprog17
Sysprog17
Ahmed Mekkawy
 
[2007 CodeEngn Conference 01] seaofglass - Linux Virus Analysis
[2007 CodeEngn Conference 01] seaofglass - Linux Virus Analysis[2007 CodeEngn Conference 01] seaofglass - Linux Virus Analysis
[2007 CodeEngn Conference 01] seaofglass - Linux Virus Analysis
GangSeok Lee
 
ch8-pv1-the-virtual-filesystem
ch8-pv1-the-virtual-filesystemch8-pv1-the-virtual-filesystem
ch8-pv1-the-virtual-filesystemyushiang fu
 
Argparse: Python command line parser
Argparse: Python command line parserArgparse: Python command line parser
Argparse: Python command line parser
Timo Stollenwerk
 
Software Exploits
Software ExploitsSoftware Exploits
Software Exploits
KevinCSmallwood
 
File management
File managementFile management
File management
lalithambiga kamaraj
 
Using MySQL in a web-scale environment
Using MySQL in a web-scale environmentUsing MySQL in a web-scale environment
Using MySQL in a web-scale environment
David Landgren
 
CyberLink LabelPrint 2.5 Exploitation Process
CyberLink LabelPrint 2.5 Exploitation ProcessCyberLink LabelPrint 2.5 Exploitation Process
CyberLink LabelPrint 2.5 Exploitation Process
Thomas Gregory
 
Bdd: Tdd and beyond the infinite
Bdd: Tdd and beyond the infiniteBdd: Tdd and beyond the infinite
Bdd: Tdd and beyond the infiniteGiordano Scalzo
 
Exploit Development: EzServer Buffer Overflow oleh Tom Gregory
Exploit Development: EzServer Buffer Overflow oleh Tom GregoryExploit Development: EzServer Buffer Overflow oleh Tom Gregory
Exploit Development: EzServer Buffer Overflow oleh Tom Gregory
zakiakhmad
 
Programming Under Linux In Python
Programming Under Linux In PythonProgramming Under Linux In Python
Programming Under Linux In Python
Marwan Osman
 
Pry at the Ruby Drink-up of Sophia, February 2012
Pry at the Ruby Drink-up of Sophia, February 2012Pry at the Ruby Drink-up of Sophia, February 2012
Pry at the Ruby Drink-up of Sophia, February 2012
rivierarb
 
File handling
File handlingFile handling
File handling
Ans Ali
 
Rust LDN 24 7 19 Oxidising the Command Line
Rust LDN 24 7 19 Oxidising the Command LineRust LDN 24 7 19 Oxidising the Command Line
Rust LDN 24 7 19 Oxidising the Command Line
Matt Provost
 
Whatsnew in-perl
Whatsnew in-perlWhatsnew in-perl
Whatsnew in-perl
daoswald
 

What's hot (20)

File management
File managementFile management
File management
 
The bones of a nice Python script
The bones of a nice Python scriptThe bones of a nice Python script
The bones of a nice Python script
 
Unit 6
Unit 6Unit 6
Unit 6
 
Sysprog17
Sysprog17Sysprog17
Sysprog17
 
certificationsold
certificationsoldcertificationsold
certificationsold
 
[2007 CodeEngn Conference 01] seaofglass - Linux Virus Analysis
[2007 CodeEngn Conference 01] seaofglass - Linux Virus Analysis[2007 CodeEngn Conference 01] seaofglass - Linux Virus Analysis
[2007 CodeEngn Conference 01] seaofglass - Linux Virus Analysis
 
Auxiliary
AuxiliaryAuxiliary
Auxiliary
 
ch8-pv1-the-virtual-filesystem
ch8-pv1-the-virtual-filesystemch8-pv1-the-virtual-filesystem
ch8-pv1-the-virtual-filesystem
 
Argparse: Python command line parser
Argparse: Python command line parserArgparse: Python command line parser
Argparse: Python command line parser
 
Software Exploits
Software ExploitsSoftware Exploits
Software Exploits
 
File management
File managementFile management
File management
 
Using MySQL in a web-scale environment
Using MySQL in a web-scale environmentUsing MySQL in a web-scale environment
Using MySQL in a web-scale environment
 
CyberLink LabelPrint 2.5 Exploitation Process
CyberLink LabelPrint 2.5 Exploitation ProcessCyberLink LabelPrint 2.5 Exploitation Process
CyberLink LabelPrint 2.5 Exploitation Process
 
Bdd: Tdd and beyond the infinite
Bdd: Tdd and beyond the infiniteBdd: Tdd and beyond the infinite
Bdd: Tdd and beyond the infinite
 
Exploit Development: EzServer Buffer Overflow oleh Tom Gregory
Exploit Development: EzServer Buffer Overflow oleh Tom GregoryExploit Development: EzServer Buffer Overflow oleh Tom Gregory
Exploit Development: EzServer Buffer Overflow oleh Tom Gregory
 
Programming Under Linux In Python
Programming Under Linux In PythonProgramming Under Linux In Python
Programming Under Linux In Python
 
Pry at the Ruby Drink-up of Sophia, February 2012
Pry at the Ruby Drink-up of Sophia, February 2012Pry at the Ruby Drink-up of Sophia, February 2012
Pry at the Ruby Drink-up of Sophia, February 2012
 
File handling
File handlingFile handling
File handling
 
Rust LDN 24 7 19 Oxidising the Command Line
Rust LDN 24 7 19 Oxidising the Command LineRust LDN 24 7 19 Oxidising the Command Line
Rust LDN 24 7 19 Oxidising the Command Line
 
Whatsnew in-perl
Whatsnew in-perlWhatsnew in-perl
Whatsnew in-perl
 

Viewers also liked

Console Io Operations
Console Io OperationsConsole Io Operations
Console Io Operations
archikabhatia
 
Unit iv
Unit ivUnit iv
Unit iv
donny101
 
Formatted input and output
Formatted input and outputFormatted input and output
Formatted input and output
Online
 
Managing console
Managing consoleManaging console
Managing console
Shiva Saxena
 
Files in c++
Files in c++Files in c++
Files in c++
Selvin Josy Bai Somu
 
C++ Files and Streams
C++ Files and Streams C++ Files and Streams
C++ Files and Streams
Ahmed Farag
 

Viewers also liked (6)

Console Io Operations
Console Io OperationsConsole Io Operations
Console Io Operations
 
Unit iv
Unit ivUnit iv
Unit iv
 
Formatted input and output
Formatted input and outputFormatted input and output
Formatted input and output
 
Managing console
Managing consoleManaging console
Managing console
 
Files in c++
Files in c++Files in c++
Files in c++
 
C++ Files and Streams
C++ Files and Streams C++ Files and Streams
C++ Files and Streams
 

Similar to Vcs26

File handling in c
File handling in cFile handling in c
File handling in c
mohit biswal
 
File in C language
File in C languageFile in C language
File in C language
Manash Kumar Mondal
 
File in c
File in cFile in c
File in c
Prabhu Govind
 
File handling(some slides only)
File handling(some slides only)File handling(some slides only)
File handling(some slides only)
Kamlesh Nishad
 
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 in c language
File handling in c languageFile handling in c language
File handling in c language
Harish Gyanani
 
C Language Unit-5
C Language Unit-5C Language Unit-5
C Language Unit-5
kasaragadda srinivasrao
 
Data structures
Data structuresData structures
Data structures
gayatrigayu1
 
File Handling in C Programming
File Handling in C ProgrammingFile Handling in C Programming
File Handling in C Programming
RavindraSalunke3
 
Unit5 (2)
Unit5 (2)Unit5 (2)
Unit5 (2)mrecedu
 
File Handling in c.ppt
File Handling in c.pptFile Handling in c.ppt
File Handling in c.ppt
BhumaNagaPavan
 
File handling-c
File handling-cFile handling-c
Advance C Programming UNIT 4-FILE HANDLING IN C.pdf
Advance C Programming UNIT 4-FILE HANDLING IN C.pdfAdvance C Programming UNIT 4-FILE HANDLING IN C.pdf
Advance C Programming UNIT 4-FILE HANDLING IN C.pdf
sangeeta borde
 
File handling in C
File handling in CFile handling in C
File handling in C
Kamal Acharya
 
ppt5-190810161800 (1).pdf
ppt5-190810161800 (1).pdfppt5-190810161800 (1).pdf
ppt5-190810161800 (1).pdf
MalligaarjunanN
 
Files_in_C.ppt
Files_in_C.pptFiles_in_C.ppt
Files_in_C.ppt
kasthurimukila
 
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 examplesMuhammed Thanveer M
 

Similar to Vcs26 (20)

File handling in c
File handling in cFile handling in c
File handling in c
 
14. fiile io
14. fiile io14. fiile io
14. fiile io
 
File in C language
File in C languageFile in C language
File in C language
 
File in c
File in cFile in c
File in c
 
Unit5 C
Unit5 C Unit5 C
Unit5 C
 
File handling(some slides only)
File handling(some slides only)File handling(some slides only)
File handling(some slides only)
 
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 in c language
File handling in c languageFile handling in c language
File handling in c language
 
C Language Unit-5
C Language Unit-5C Language Unit-5
C Language Unit-5
 
Data structures
Data structuresData structures
Data structures
 
File Handling in C Programming
File Handling in C ProgrammingFile Handling in C Programming
File Handling in C Programming
 
7.0 files and c input
7.0 files and c input7.0 files and c input
7.0 files and c input
 
Unit5 (2)
Unit5 (2)Unit5 (2)
Unit5 (2)
 
File Handling in c.ppt
File Handling in c.pptFile Handling in c.ppt
File Handling in c.ppt
 
File handling-c
File handling-cFile handling-c
File handling-c
 
Advance C Programming UNIT 4-FILE HANDLING IN C.pdf
Advance C Programming UNIT 4-FILE HANDLING IN C.pdfAdvance C Programming UNIT 4-FILE HANDLING IN C.pdf
Advance C Programming UNIT 4-FILE HANDLING IN C.pdf
 
File handling in C
File handling in CFile handling in C
File handling in C
 
ppt5-190810161800 (1).pdf
ppt5-190810161800 (1).pdfppt5-190810161800 (1).pdf
ppt5-190810161800 (1).pdf
 
Files_in_C.ppt
Files_in_C.pptFiles_in_C.ppt
Files_in_C.ppt
 
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
 

More from Malikireddy Bramhananda Reddy

DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDY
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDYDATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDY
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDYMalikireddy Bramhananda Reddy
 
DATA STRUCTURES AND ALGORITHMS UNIT-3 TREES PREPARED BY M V BRAHMANANDA REDDY
DATA STRUCTURES AND ALGORITHMS UNIT-3 TREES PREPARED BY M V BRAHMANANDA REDDYDATA STRUCTURES AND ALGORITHMS UNIT-3 TREES PREPARED BY M V BRAHMANANDA REDDY
DATA STRUCTURES AND ALGORITHMS UNIT-3 TREES PREPARED BY M V BRAHMANANDA REDDYMalikireddy Bramhananda Reddy
 
Datastructures and algorithms prepared by M.V.Brehmanada Reddy
Datastructures and algorithms prepared by M.V.Brehmanada ReddyDatastructures and algorithms prepared by M.V.Brehmanada Reddy
Datastructures and algorithms prepared by M.V.Brehmanada ReddyMalikireddy Bramhananda Reddy
 
C notes by m v b reddy(gitam)imp notes all units notes 5 unit order
C notes by m v b  reddy(gitam)imp  notes  all units notes  5 unit orderC notes by m v b  reddy(gitam)imp  notes  all units notes  5 unit order
C notes by m v b reddy(gitam)imp notes all units notes 5 unit orderMalikireddy Bramhananda Reddy
 

More from Malikireddy Bramhananda Reddy (20)

M v bramhananda reddy dsa complete notes
M v bramhananda reddy dsa complete notesM v bramhananda reddy dsa complete notes
M v bramhananda reddy dsa complete notes
 
AVL TREE PREPARED BY M V BRAHMANANDA REDDY
AVL TREE PREPARED BY M V BRAHMANANDA REDDYAVL TREE PREPARED BY M V BRAHMANANDA REDDY
AVL TREE PREPARED BY M V BRAHMANANDA REDDY
 
B-TREE PREPARED BY M V BRAHMANANDA REDDY
B-TREE PREPARED BY M V BRAHMANANDA REDDYB-TREE PREPARED BY M V BRAHMANANDA REDDY
B-TREE PREPARED BY M V BRAHMANANDA REDDY
 
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDY
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDYDATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDY
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDY
 
DATA STRUCTURES AND ALGORITHMS UNIT-3 TREES PREPARED BY M V BRAHMANANDA REDDY
DATA STRUCTURES AND ALGORITHMS UNIT-3 TREES PREPARED BY M V BRAHMANANDA REDDYDATA STRUCTURES AND ALGORITHMS UNIT-3 TREES PREPARED BY M V BRAHMANANDA REDDY
DATA STRUCTURES AND ALGORITHMS UNIT-3 TREES PREPARED BY M V BRAHMANANDA REDDY
 
Datastructures and algorithms prepared by M.V.Brehmanada Reddy
Datastructures and algorithms prepared by M.V.Brehmanada ReddyDatastructures and algorithms prepared by M.V.Brehmanada Reddy
Datastructures and algorithms prepared by M.V.Brehmanada Reddy
 
C LANGUAGE UNIT-1 PREPARED BY M V BRAHMANANDA REDDY
C LANGUAGE UNIT-1 PREPARED BY M V BRAHMANANDA REDDYC LANGUAGE UNIT-1 PREPARED BY M V BRAHMANANDA REDDY
C LANGUAGE UNIT-1 PREPARED BY M V BRAHMANANDA REDDY
 
DATASTRUCTURES UNIT-1
DATASTRUCTURES UNIT-1DATASTRUCTURES UNIT-1
DATASTRUCTURES UNIT-1
 
Data representation UNIT-1
Data representation UNIT-1Data representation UNIT-1
Data representation UNIT-1
 
C SLIDES PREPARED BY M V B REDDY
C SLIDES PREPARED BY  M V B REDDYC SLIDES PREPARED BY  M V B REDDY
C SLIDES PREPARED BY M V B REDDY
 
C AND DATASTRUCTURES PREPARED BY M V B REDDY
C AND DATASTRUCTURES PREPARED BY M V B REDDYC AND DATASTRUCTURES PREPARED BY M V B REDDY
C AND DATASTRUCTURES PREPARED BY M V B REDDY
 
C PROGRAMS
C PROGRAMSC PROGRAMS
C PROGRAMS
 
C LANGUAGE NOTES
C LANGUAGE NOTESC LANGUAGE NOTES
C LANGUAGE NOTES
 
C notes by m v b reddy(gitam)imp notes all units notes 5 unit order
C notes by m v b  reddy(gitam)imp  notes  all units notes  5 unit orderC notes by m v b  reddy(gitam)imp  notes  all units notes  5 unit order
C notes by m v b reddy(gitam)imp notes all units notes 5 unit order
 
Vcs29
Vcs29Vcs29
Vcs29
 
Vcs24
Vcs24Vcs24
Vcs24
 
Vcs23
Vcs23Vcs23
Vcs23
 
Vcs22
Vcs22Vcs22
Vcs22
 
Vcs21
Vcs21Vcs21
Vcs21
 
Vcs20
Vcs20Vcs20
Vcs20
 

Vcs26

  • 1. Unformatted Console I/O Functions main( ) { printf ( ”Delete all files Y/N” ) ; ch = getchar( ) ; /* or ch = fgetchar( ) ; */ putch ( ch ) ; putchar ( ch ) ; fputchar ( ch ) ; } printf ( ”Press any key” ) ; getch( ) ; printf ( ”Another disk Y/N” ) ; ch = getche( ) ; same char ch ;
  • 2. Peculiarities getch( ) - Doesn’t wait for enter. getche( ) - Echoes character. getchar( ) - Waits for enter. Macro. fgetchar( ) - Waits for enter. Function.
  • 3. Disk I/O High Level / Std Disk I/O Low Level Text Binary Formatted Unformatted char int fprintf( ) float fscanf( ) string char - getc ( ), fgetc( ) putc ( ), fputc( ) Reads / Writes char by char int - float - No Std. Library Function string - fgets( ), fputs( ) Reads / Writes line by line file
  • 4. Bufferred I/O Memory )) Buffer CCHH11PPRR11..CC Disk
  • 5. Displaying File Contents # include ”stdio.h” char fname[13] ; printf ( ”Enter file name” ) ; gets ( fname ) ; fopen ( ) ; main( ) { char ch ; FILE *fp ; fp = fname, ”r” while ( 1 ) { ch = getc ( ) ; if ( ch == EOF ) break ; printf ( ”%c”, ch ) ; } fclose ( ) ; } fp fp
  • 6. typedef unsigned long int i, j ; typedef unsigned long int uli ; struct employee { ___ } ; struct employee e1, e2 ; struct a { __ char *p ; } ; typedef struct a FILE ; uli i, j ; struct employee { ___ } ; typedef struct employee emp ; emp e1, e2 ; FILE *fp ;
  • 7. # include ”stdio.h” char fname[13] ; printf ( ”Enter file name” ) ; gets ( fname ) ; fopen ( ) ; main( ) { char ch ; FILE *fp ; fp = fname, ”r” while ( 1 ) { ch = getc ( ) ; if ( ch == EOF ) break ; printf ( ”%c”, ch ) ; } fclose ( ) ; } fp fp A Fresh Look Buffer 40 fp p 40 ffpp -->> pp == ffpp -->> pp ++ 11 ;;
  • 8. Tips fopen( ) - Standard Library Function to open the file. fopen ( fname, ”r” ) ; - Returns NULL if file not found. Every file ends with a char with ascii value 26. EOF is a macro. # define EOF -1 FILE is a structure defined in stdio.h getc( ) reads char also shifts pointer to next char.
  • 9. Copying Files char fname[13] , target[13] ; printf ( ”Enter source target file names” ) ; gets ( fname ) ; gets ( target ) ; ft = fopen ( target, ”w” ) ; # include ”stdio.h” fopen ( ) ; main( ) { char ch ; FILE *fs, *ft ; fs = fname, ”r” while ( 1 ) { ch = getc ( ) ; if ( ch == EOF ) break ; putc ( ) ; ch, ft } fclose ( ) ; fs fs fclose ( ft ) ; }
  • 10. Copying Files char fname[13] , target[13] ; printf ( ”Enter source target file names” ) ; gets ( fname ) ; gets ( target ) ; ft = fopen ( target, ”w” ) ; # include ”stdio.h” fopen ( ) ; main( ) { char ch ; FILE *fs, *ft ; fs = fname, ”r” while ( 1 ) { ch = getc ( ) ; if ( ch == EOF ) break ; putc ( ) ; ch, ft } fclose ( ) ; fs fs fclose ( ft ) ; }