Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 6P. 1Winter Quarter I/O in C Lecture 6.

Slides:



Advertisements
Similar presentations
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.
Advertisements

Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 16P. 1Winter Quarter Strings Lecture 16.
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 12P. 1Winter Quarter User-Written Functions.
Engineering EG167C - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect M1 P. 1Winter Quarter Midterm I Review.
BITS Pilani, Pilani Campus TA C252 Computer Programming - II Vikas Singh File Handling.
Dale Roberts Basic I/O – printf() CSCI 230 Department of Computer and Information Science, School of Science, IUPUI Dale Roberts, Lecturer Department of.
Lecture 2 Introduction to C Programming
CS1061 C Programming Lecture 16: Formatted I/0 A. O’Riordan, 2004.
1 Chapter 9 - Formatted Input/Output Outline 9.1Introduction 9.2Streams 9.3Formatting Output with printf 9.4Printing Integers 9.5Printing Floating-Point.
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 11P. 1Winter Quarter Arrays Lecture 11.
Chapter 9 Formatted Input/Output Acknowledgment The notes are adapted from those provided by Deitel & Associates, Inc. and Pearson Education Inc.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 9 - Formatted Input/Output Outline 9.1Introduction.
1 Key Concepts:  Data types in C.  What is a variable?  Variable Declaration  Variable Initialization  Printf()  Scanf()  Working with numbers in.
 2007 Pearson Education, Inc. All rights reserved C Formatted Input/Output.
1 CSE1301 Computer Programming: Lecture 9 Input/Output.
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect M1 P. 1Winter Quarter Midterm I Review Topics.
 2000 Prentice Hall, Inc. All rights reserved. Chapter 9 - Formatted Input/Output Outline 9.1Introduction 9.2Streams 9.3Formatting Output with printf.
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect M2P. 1Winter Quarter Midterm 2 Review Topics.
Basic Input/Output and Variables Ethan Cerami New York
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 9P. 1Winter Quarter Switch Case Structures.
Console and File I/O - Basics Rudra Dutta CSC Spring 2007, Section 001.
C - Input & Output When we are saying Input that means to feed some data into program. This can be given in the form of file or from command line. C programming.
CS 161 Introduction to Programming and Problem Solving Chapter 13 Console IO Herbert G. Mayer, PSU Status 9/8/2014 Initial content copied verbatim from.
Spring 2005, Gülcihan Özdemir Dağ Lecture 4, Page 1 BIL104E: Introduction to Scientific and Engineering Computing, Spring Lecture 4 Outline 4.0 Reading.
 2007 Pearson Education, Inc. All rights reserved C Formatted Input/Output.
Chapter 18 I/O in C. Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display Standard C Library I/O commands.
Files Programs and data are stored on disk in structures called files Examples Turbo C++ - binary file Word binary file lab1.c - text file lab1.data.
Ping Zhang 10/08/2010.  You can get data from the user (input) and display information to the user (output).  However, you must include the library.
Input/Output  Input/Output operations are performed using input/output functions  Common input/output functions are provided as part of C’s standard.
 2000 Prentice Hall, Inc. All rights reserved. Chapter 9 - Formatted Input/Output Outline 9.1Introduction 9.2Streams 9.3Formatting Output with printf.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Streams Streams –Sequences of characters organized.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 9 - Formatted Input/Output Outline 9.1Introduction.
Chapter 5: Data Input and Output Department of Computer Science Foundation Year Program Umm Alqura University, Makkah Computer Programming Skills
Chapter 9 Formatted Input/Output. Objectives In this chapter, you will learn: –To understand input and output streams. –To be able to use all print formatting.
Chapter 9 Formatted Input/Output Associate Prof. Yuh-Shyan Chen Dept. of Computer Science and Information Engineering National Chung-Cheng University.
EPSII 59:006 Spring Introduction In this lecture  Formatted Input/Output scanf and printf  Streams (input and output) gets, puts, getchar, putchar.
Chapter 9 - Formatted Input/Output Outline 9.1Introduction 9.2Streams 9.3Formatting Output with printf 9.4Printing Integers 9.5Printing Floating-Point.
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.
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.
CHAPTER 2 PART #3 INPUT - OUTPUT 1 st semester King Saud University College of Applied studies and Community Service Csc
Engineering H192 - Computer Programming Gateway Engineering Education Coalition Lect 25P. 1Winter Quarter C++: I/O and Classes Lecture 25.
C Programming Lecture 5 : Basic standard I/O Lecture notes : courtesy of Ohio Supercomputing Center, science and technolgy support.
Structure of a C program Preprocessor directive (header file) Program statement } Preprocessor directive Global variable declaration Comments Local variable.
CSE1301 Computer Programming: Lecture 6 Input/Output.
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 11P. 1Winter Quarter Arrays Lecture 11.
Department of Electronic & Electrical Engineering IO reading and writing variables scanf printf format strings "%d %c %f"
Files A collection of related data treated as a unit. Two types Text
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.
CCSA 221 Programming in C INPUT AND OUTPUT OPERATIONS IN C – PART 1 1.
BIL 104E Introduction to Scientific and Engineering Computing Lecture 2.
Formatted I/O ä ä Standard Output ä ä printf() family of functions ä ä Standard Input ä ä scanf() family of functions.
Introduction to Computing Lecture 03: Basic input / output operations Introduction to Computing Lecture 03: Basic input / output operations Assist.Prof.Dr.
Chapter 9 - Formatted Input/Output
C Formatted Input/Output
Chapter 7 Text Input/Output Objectives
INTRODUCTION Every language has some features that provides interaction between the program and the user of the program. C language uses the reference.
Chapter 7 Text Input/Output Objectives
Plan for the Day: I/O (beyond scanf and printf)
CS111 Computer Programming
CSE1320 Files in C Dr. Sajib Datta
CSE1320 Files in C Dr. Sajib Datta
Input and Output Lecture 4.
Input/Output Input/Output operations are performed using input/output functions Common input/output functions are provided as part of C’s standard input/output.
C Formatted Input / Output Review and Lab Assignments
CSI 121 Structured Programming Language Lecture 7: Input/Output
I/O in C Lecture 6 Winter Quarter Engineering H192 Winter 2005
Chapter 9 - Formatted Input/Output
CS1100 Computational Engineering
C How to Program, 6/e © by Pearson Education, Inc. All Rights Reserved.
Presentation transcript:

Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 6P. 1Winter Quarter I/O in C Lecture 6

Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 6P. 2Winter Quarter Input/Output in C C has no built-in statements for input or output. A library of functions is supplied to perform these operations. The I/O library functions are listed the “header” file. You do not need to memorize them, just be familiar with them.

Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 6P. 3Winter Quarter Streams All input and output is performed with streams. A "stream" is a sequence of characters organized into lines. Each line consists of zero or more characters and ends with the "newline" character. ANSI C standards specify that the system must support lines that are at least 254 characters in length (including the newline character).

Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 6P. 4Winter Quarter Types of Streams in C Standard input stream is called "stdin" and is normally connected to the keyboard Standard output stream is called "stdout" and is normally connected to the display screen. Standard error stream is called "stderr" and is also normally connected to the screen.

Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 6P. 5Winter Quarter Formatted Output with printf printf ( ) ; This function provides for formatted output to the screen. The syntax is: printf ( “format”, var1, var2, … ) ; The “format” includes a listing of the data types of the variables to be output and, optionally, some text and control character(s). Example: float a ; int b ; scanf ( “%f%d”, &a, &b ) ; printf ( “You entered %f and %d \n”, a, b ) ;

Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 6P. 6Winter Quarter Formatted Output with printf Format Conversion Specifiers: d -- displays a decimal (base 10) integer l -- used with other specifiers to indicate a "long" e -- displays a floating point value in exponential notation f -- displays a floating point value g -- displays a number in either "e" or "f" format c -- displays a single character s -- displays a string of characters

Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 6P. 7Winter Quarter Input/Output in C scanf ( ) ; This function provides for formatted input from the keyboard. The syntax is: scanf ( “format”, &var1, &var2, …) ; The “format” is a listing of the data types of the variables to be input and the & in front of each variable name tells the system WHERE to store the value that is input. It provides the address for the variable. Example: float a; int b; scanf (“%f%d”, &a, &b);

Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 6P. 8Winter Quarter Input/Output in C getchar ( ) ; This function provides for getting exactly one character from the keyboard. Example: char ch; ch = getchar ( ) ;

Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 6P. 9Winter Quarter Input/Output in C putchar (char) ; This function provides for printing exactly one character to the screen. Example: char ch; ch = getchar ( ) ; /* input a character from kbd*/ putchar (ch) ; /* display it on the screen */

Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 6P. 10Winter Quarter Input/Output in C getc ( *file ) ; This function is similar to getchar( ) except the input can be from the keyboard or a file. Example: char ch; ch = getc (stdin) ;/* input from keyboard */ ch = getc (fileptr) ;/* input from a file */

Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 6P. 11Winter Quarter Input/Output in C putc ( char, *file ) ; This function is similar to putchar ( ) except the output can be to the screen or a file. Example: char ch; ch = getc (stdin) ;/* input from keyboard */ putc (ch, stdout) ; /* output to the screen */ putc (ch, outfileptr) ; /*output to a file */