C Programming Lecture 5 : Basic standard I/O Lecture notes : courtesy of Ohio Supercomputing Center, science and technolgy support.

Slides:



Advertisements
Similar presentations
Standard I/O Lesson Outline
Advertisements

Standard I/O Lesson CS1313 Spring Standard I/O Lesson Outline 1.Standard I/O Lesson Outline 2.Output via printf 3.Placeholders 4.Placeholders for.
Dale Roberts Basic I/O – scanf() CSCI 230 Department of Computer and Information Science, School of Science, IUPUI Dale Roberts, Lecturer Department of.
1 Chapter 9 - Formatted Input/Output Outline 9.1Introduction 9.2Streams 9.3Formatting Output with printf 9.4Printing Integers 9.5Printing Floating-Point.
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.
 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 6P. 1Winter Quarter I/O in C Lecture 6.
Testing a program Remove syntax and link errors: Look at compiler comments where errors occurred and check program around these lines Run time errors:
Chapter 18 I/O in C. Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display Standard C Library I/O commands.
CMSC 104, Version 8/061L18Functions1.ppt Functions, Part 1 of 4 Topics Using Predefined Functions Programmer-Defined Functions Using Input Parameters Function.
Computer Science 210 Computer Organization Introduction to C.
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.
C Programming Lecture 3. The Three Stages of Compiling a Program b The preprocessor is invoked The source code is modified b The compiler itself is invoked.
CMPE13 Cyrus Bazeghi Chapter 18 I/O in C. CMPE Standard C Library I/O commands are not included as part of the C language. Instead, they are part.
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.
Yu Yuanming CSCI2100B Data Structures Tutorial 3
Strlen() implementation /* strlen : return length of string s */ int strlen(char *s) { int n; for (n = 0 ; s[n] != ‘\0’ ; n++) ; return n; } /* strlen.
Reading the data from the input devices and displaying the results on the screen are the two main tasks of any program. To perform these tasks user friendly.
C Programming Lecture 4 : Variables , Data Types
CHAPTER 2 PART #3 INPUT - OUTPUT 1 st semester King Saud University College of Applied studies and Community Service Csc
How to start Visual Studio 2008 or 2010 (command-line program)
Chapter 18 I/O in C.
Structure of a C program Preprocessor directive (header file) Program statement } Preprocessor directive Global variable declaration Comments Local variable.
CMSC 202 Java Console I/O. July 25, Introduction Displaying text to the user and allowing the user to enter text are fundamental operations performed.
CSCI 3133 Programming with C Instructor: Bindra Shrestha University of Houston – Clear Lake.
Functions: Part 2 of /11/10: Lecture 16 CMSC 104, Section 0101 John Y. Park 1.
CSE1301 Computer Programming: Lecture 6 Input/Output.
E-1 University of Washington Computer Programming I Lecture 5: Input and Output (I/O) © 2000 UW CSE.
Operating System Discussion Section. The Basics of C Reference: Lecture note 2 and 3 notes.html.
Chapter 8 Characters and Strings. Objectives In this chapter, you will learn: –To be able to use the functions of the character handling library ( ctype).
Exercise 1 #include int main() { printf(“Hello C Programming!\n”); return 0; } 1.Run your Visual Studio 2008 or Create a new “project” and add.
Computer Programming for Engineers
Homework 1 (due:April 8th) Deadline : April 8th 11:59pm Where to submit? eClass “ 과제방 ” ( How to submit? Create a folder. The name.
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To understand the basic properties and characteristics of external files ❏ To.
IO revisited CSE 2451 Rong Shi. stdio.h Functions – printf – scanf(normally stops at whitespace) – fgets – sscanf Standard streams – stdin(defaults to.
NOTE: C programs consist of functions one of which must be main. C programs consist of functions one of which must be main. Every C program begins executing.
CCSA 221 Programming in C INPUT AND OUTPUT OPERATIONS IN C – PART 1 1.
Chapter 18 I/O in C Original slides from Gregory Byrd, North Carolina State University Modified slides by C. Wilcox, Y. Malaiya Colorado State University.
Chapter 1 slides1 What is C? A high-level language that is extremely useful for engineering computations. A computer language that has endured for almost.
CSCE 206 Structured Programming in C
Zhang Hongyi CSCI2100B Data Structures Tutorial 3
Chapter 7 Text Input/Output Objectives
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
Chapter 3: I/O Management
Chapter 18 I/O in C.
Introduction to C CSE 2031 Fall /3/ :33 AM.
Getting Started with C.
Plan for the Day: I/O (beyond scanf and printf)
Programming in C Input / Output.
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
Lecture 13 Input/Output Files.
I/O in C Lecture 6 Winter Quarter Engineering H192 Winter 2005
Module 12 Input and Output
Introduction to C EECS May 2019.
Introduction to C CSE 2031 Fall /15/2019 8:26 AM.
Presentation transcript:

C Programming Lecture 5 : Basic standard I/O Lecture notes : courtesy of Ohio Supercomputing Center, science and technolgy support

Standard Input/Output (I/O) Preconnected input and output channels between a computer program and its environment(typically a text terminal). Standard input : text input from keyboard Standard output text output written to display Standard error : another text output written to display for error messaging

Standard I/O library Library A collection of subroutines (functions) used to develop software Standard library Library that is made available in every implementation of a programming language Same interface(parameter type), same functionality in different systems Standard I/O library Standard library for processing I/O

printf function printf(control string,argument list); Control string contains Literal text to be displayed format specifiers Special characters Arguments can be Variable, function, expression, constant # of argument list must match the # of format identifiers

printf example Output : i = 2 f = c = 5

printf format specifiers

printf examples output: pi = pi = 3.14 pi = output : i = 2 f = c = 5

scanf function Accept formatted text input Output : 27  ---- keyboard input entered n = 27 double of n = 54 triple of n = 81

gets(), puts() functions line based string I/O functions Prototype char* gets(char *BUF); Read characters from standard input until a newline is found int puts(const char *s); Writes a string s to the standard output. #include #define MAX_LINES 256 int main() { char line[MAX_LINES]; printf(“string input :”); gets(line); printf(“the input string is : ”); puts(line); return 0; }

redirection Input redirection Gets standard input from a file “inputFile.txt” program.exe < inputFile.txt Output redirection writes standard output to a file “outputFile.txt” program.exe > outputFile.txt Combination Gets standard input from a file “inputFile.txt” and writes standard output to a file “outputFile.txt” program.exe outputFile.txt

Exercise Write a program that converts meter-type height into [feet(integer),inch(float)]-type height. Your program should get one float typed height value as an input and prints integer typed feet value and the rest of the height is represented as inch type. (1m=3.2808ft=39.37inch) Ex) 1.80meter -> 5feet 10.9inch use automatic type conversion 1/2 = 0 (?), 3/2 = 1 (?) (ex) int a; float b; b = 3.6/2.0; a=b; printf(“a=%d, b=%f\n”,a,b);