IO revisited CSE 2451 Rong Shi. stdio.h Functions – printf – scanf(normally stops at whitespace) – fgets – sscanf Standard streams – stdin(defaults to.

Slides:



Advertisements
Similar presentations
Lecture 3 Some commonly used C programming tricks. The system command Project No. 1: A warm-up project.
Advertisements

Character Arrays (Single-Dimensional Arrays) A char data type is needed to hold a single character. To store a string we have to use a single-dimensional.
Using Files Declare a variable, called file pointer, of type FILE * Use function fopen to open a named file and associate this file with the file pointer.
UNIT 15 File Processing.
Strings Input/Output scanf and printf sscanf and sprintf gets and puts.
Character String Manipulation. Overview Character string functions sscanf() function sprintf() function.
Character String Manipulation. Overview Character string functions sscanf() function snprintf() function.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Introduction Data files –Can be created, updated,
CS1061 C Programming Lecture 17: Steams and Character I/O A. O’Riordan, 2004.
File I/O.
1 CSE1301 Computer Programming: Lecture 9 Input/Output.
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 6P. 1Winter Quarter I/O in C Lecture 6.
Console and File I/O - Basics Rudra Dutta CSC Spring 2007, Section 001.
Binary Search Tree For a node: The left subtree contains nodes with keys less than the node's key. The right subtree contains nodes with keys greater than.
Lecture 13. Outline Standard Input and Output Standard Input and Output (I/O)– Review & more Buffered/unbuffered input Character I/O Formatted I/O Redirecting.
Standard Input and Output. Overview Data communication with a C program and the outside world is performed through files Files are a non-volatile way.
CP104 Introduction to Programming File I/O Lecture 33 __ 1 File Input/Output Text file and binary files File Input/output File input / output functions.
Adv. UNIX:io/91 Advanced UNIX v Objectives of these slides: –look in some detail at standard input and output in C Special Topics in Comp.
22. FILE INPUT/OUTPUT. File Pointers and Streams Declarations of functions that perform file I/O appear in. Each function requires a file pointer as a.
Chapter 18 I/O in C.
C Programming Lecture 5 : Basic standard I/O Lecture notes : courtesy of Ohio Supercomputing Center, science and technolgy support.
1 Lecture09: File I/O 5/6/2013 Slides modified from Yin Lou, Cornell CS2022: Introduction to C.
File IO and command line input CSE 2451 Rong Shi.
File I/O, Project 1: List ADT Bryce Boe 2013/07/02 CS24, Summer 2013 C.
Lecture 8a: File I/O BJ Furman 21MAR2011. Learning Objectives Explain what is meant by a data stream Explain the concept of a ‘file’ Open and close files.
Memory Layout, File I/O Bryce Boe 2013/06/27 CS24, Summer 2013 C.
Chapter 11: Data Files and File Processing Files and streams Creating a sequential access file Reading data from a sequential access file Using fgetc()
Using Files Declare a variable, called file pointer, of type FILE * Use function fopen to open a named file and associate this file with the file pointer.
24-2 Perform File I/O using file pointers FILE * data-type Opening and closing files Character Input and Output String Input and Output Related Chapter:
CSE1301 Computer Programming: Lecture 6 Input/Output.
CS 261 – Recitation 7 Spring 2015 Oregon State University School of Electrical Engineering and Computer Science.
GAME203 – C Files stdio.h C standard Input/Output “getchar()”
Files A collection of related data treated as a unit. Two types Text
C is a high level language (HLL)
Lecture 20: C File Processing. Why Using Files? Storage of data in variables and arrays is temporary Data lost when a program terminates. Files are used.
Connecting to Files In order to read or write to a file, we need to make a connection to it. There are several functions for doing this. fopen() – makes.
Introduction to Computing Lecture 03: Basic input / output operations Introduction to Computing Lecture 03: Basic input / output operations Assist.Prof.Dr.
Strings CSCI 112: Programming in C.
INTRODUCTION Every language has some features that provides interaction between the program and the user of the program. C language uses the reference.
File I/O.
Introduction to C CSE 2031 Fall /3/ :33 AM.
CS 261 – Recitation 7 Fall 2013 Oregon State University
CSC215 Lecture Input and Output.
Plan for the Day: I/O (beyond scanf and printf)
Computer Science 210 Computer Organization
CS111 Computer Programming
CSE1320 Files in C Dr. Sajib Datta
CSE1320 Files in C Dr. Sajib Datta
Programming in C Input / Output.
Computer Science 210 Computer Organization
Programming in C Input / Output.
Files I/O, Streams, I/O Redirection, Reading with fscanf
CSE1320 Files in C Dr. Sajib Datta
CSI 121 Structured Programming Language Lecture 7: Input/Output
I/O in C Lecture 6 Winter Quarter Engineering H192 Winter 2005
CSC215 Lecture Input and Output.
CSC215 Lecture Input and Output.
Input/Output and the Operating Systems
sscanf()- string scan function
Line at a time I/O with fgets() and fputs()
Programming in C Input / Output.
Weeks 9-10 IO System Calls Standard IO (stdin, stdout) and Pipes
ECE 103 Engineering Programming Chapter 51 Random Numbers
Module 12 Input and Output
CS1100 Computational Engineering
Chapter 11 Files chap8.
CSc 352 File I/O Saumya Debray Dept. of Computer Science
Introduction to C CSE 2031 Fall /15/2019 8:26 AM.
I/O CS580U - Fall 2018.
Chapter 18 I/O in C.
Presentation transcript:

IO revisited CSE 2451 Rong Shi

stdio.h Functions – printf – scanf(normally stops at whitespace) – fgets – sscanf Standard streams – stdin(defaults to keyboard) stdin – stdout(defaults to console) stdout – stderr(defaults to console) stderr

scanf and incorrect input scanf input is based on pattern matching If incorrect input is entered, the pattern is not matched and the input characters remain in the buffer See scanftest.c

fgets – get string from stream char *fgets(char *s, int size, FILE *stream); – Read in size - 1 characters from the stream and stores it into *s pointer. – The string is automatically null-terminated. – fgets stops reading in characters if it reaches an EOF or newline. Ex: char s[100]; fgets(s, sizeof(s), stdin); // read a line from stdin Use sscanf to process the string

sscanf – read formatted data from string int sscanf(const char *str, const char *format,...); – *str is a string / character array / pointer to character – *format is a string literal – Additional arguments are pointers to the types in *format Ex: int i; char s[100]; fgets(s, sizeof(s), stdin); // read a line from stdin sscanf (s,"%d", &i);

IO redirection When running an executable > redirects output < redirects input | pipe (stdout from one program to stdin of another) Examples: testprog > fileout (output of testprog goes to fileout) testprog < filein (input of testprog comes from filein) prog1 | prog2 (input of prog2 comes from output of prog1)