Chapter 7 Formatted input and output. 7.1 introduction Tax:12345.500000 This result is correct; but it would be better Maybe as $13,545.50 Make formatting.

Slides:



Advertisements
Similar presentations
This Time Whitespace and Input/Output revisited The Programming cycle Boolean Operators The “if” control structure LAB –Write a program that takes an integer.
Advertisements

Chapter 9 Pointers and Dynamic Arrays. Overview 9.1 Pointers 9.2 Dynamic Arrays.
Introduction to Programming Lecture 39. Copy Constructor.
Chapter 3. Expressions and Interactivity CSC125 Introduction to C++
Dale Roberts Basic I/O – scanf() CSCI 230 Department of Computer and Information Science, School of Science, IUPUI Dale Roberts, Lecturer Department of.
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.
41 A Depth Program #include int main(void) { int inches, feet, fathoms; //declarations fathoms = 7; feet = 6 * fathoms; inches = 12 * feet; printf(“Wreck.
1 Lecture 2  Input-Process-Output  The Hello-world program  A Feet-to-inches program  Variables, expressions, assignments & initialization  printf()
CS201 – Expressions & I/O. Precedence What is the value of * 4 ? 20 or 14 ? Without parentheses, there are a set of rules to fall back on. Unary.
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.
Declarations/Data Types/Statements. Assignments Due – Homework 1 Reading – Chapter 2 – Lab 1 – due Monday.
 2007 Pearson Education, Inc. All rights reserved C Formatted Input/Output.
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To understand the structure of a C-language program. ❏ To write your first C.
C Formatted Input/Output /* Using Integer Conversion Specifiers */ #include int main ( ) { printf( "%d\n", 455 ); printf( "%i\n", 455 ); printf( "%d\n",
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.
Lecture No: 16. The scanf() function In C programming language, the scanf() function is used to read information from standard input device (keyboard).
 2007 Pearson Education, Inc. All rights reserved C Formatted Input/Output.
Introduction to programming Language C, Data Types, Variables, Constants. Basics of C –Every program consists of one or more functions and must have main.
Expressions and Interactivity Chapter 3. 2 The cin Object Standard input object Like cout, requires iostream file Used to read input from keyboard Often.
11 Chapter 3 DECISION STRUCTURES CONT’D. 22 FORMATTING FLOATING-POINT VALUES WITH THE DecimalFormat CLASS We can use the DecimalFormat class to control.
 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.
1 IPC144 Session 11 The C Programming Language. 2 Objectives To format a #define statement correctly To use a #define statement in a C program To construct.
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 2 : Overview of C By Suraya Alias. /*The classic HelloWorld */ #include int main(void) { printf(“Hello World!!"); return 0; }
Chapter 9 Formatted Input/Output Associate Prof. Yuh-Shyan Chen Dept. of Computer Science and Information Engineering National Chung-Cheng University.
 Pearson Education, Inc. All rights reserved Formatted Output.
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.
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To understand design concepts for fixed-length and variable- length strings ❏
CNG 140 C Programming (Lecture set 9) Spring Chapter 9 Character Strings.
Programming I Introduction Introduction The only way to learn a new programming language is by writing programs in it. The first program to.
Sales person receive RM200/week plus 9% of their gross sales for that week. Write an algorithms to calculate the sales person’s earning from the input.
Chapter 3 Processing and Interactive Input. 2 Assignment  The general syntax for an assignment statement is variable = operand; The operand to the right.
CNG 140 C Programming Lecture Notes 2 Processing and Interactive Input Spring 2007.
A First Book of ANSI C Fourth Edition Chapter 3 Processing and Interactive Input.
Constants Numeric Constants Integer Constants Floating Point Constants Character Constants Expressions Arithmetic Operators Assignment Operators Relational.
Chapter 3: Formatted Input/Output Copyright © 2008 W. W. Norton & Company. All rights reserved. 1 Chapter 3 Formatted Input/Output.
3. FORMATTED INPUT/OUTPUT. The printf Function The first argument in a call of printf is a string, which may contain both ordinary characters and conversion.
Chapter-4 Managing input and Output operation.  Reading, processing and writing of data are three essential functions of a computer program.  Most programs.
S CCS 200: I NTERACTIVE I NPUT Lect. Napat Amphaiphan.
Operating System Discussion Section. The Basics of C Reference: Lecture note 2 and 3 notes.html.
Department of Electronic & Electrical Engineering IO reading and writing variables scanf printf format strings "%d %c %f"
A.Abhari CPS1251 Topic 2: C Overview C Language Elements Variable Declaration and Data Types Statement Execution C Program Layout Formatting Output Interactive.
Files A collection of related data treated as a unit. Two types Text
Dr. Sajib Datta Jan 21,  Declare a variable ◦ int height; [note that no value is still assigned]  Assign a variable a value ◦ height =
Chapter 3: Formatted Input/Output 1 Chapter 3 Formatted Input/Output.
+ Note On the Use of Different Data Types Use the data type that conserves memory and still accomplishes the desired purpose. For example, depending on.
CCSA 221 Programming in C CHAPTER 3 COMPILING AND RUNNING YOUR FIRST PROGRAM 1 ALHANOUF ALAMR.
CSCI 125 & 161 / ENGR 144 Lecture 6 Martin van Bommel.
CSC 482/582: Computer Security
ECE Application Programming
Input/output.
Unit-4, Chapter-2 Managing Input and Output Operations
Introduction to C CSE 2031 Fall /3/ :33 AM.
Chapter 3: Expressions and Interactivity.
A First Book of ANSI C Fourth Edition
Administrative things
DATA HANDLING.
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.
A First Book of ANSI C Fourth Edition
IPC144 Introduction to Programming Using C Week 8 – Lesson 1
Conversion Check your class notes and given examples at class.
Engineering Problem Solving with C++ An Object Based Approach
Engineering Problem Solving with C++ An Object Based Approach
Introduction to C CSE 2031 Fall /15/2019 8:26 AM.
Presentation transcript:

Chapter 7 Formatted input and output

7.1 introduction Tax: This result is correct; but it would be better Maybe as $13, Make formatting of input and output

7.2 interactive versus batch programs A data file consists of lines into which we type data values. A computer program that operates in this manner is said to have batch input If we want to save the output of a program in a file, we can direct it to a computer file. In this case the program has batch output.

7.5 OUTPUT FORMATTING 1. right-adjusted 2. Left-adjusted 3. a specified fill character. A fill character is any character that replaces the leading or trailing blanks in an output field. Specifying a Print Field of Fixed Width

Example 7.2 Printf(“%10d”, number); Specifying Left-Adjusted Printing in a Fixed-Width Field A minus after the symbol %

Example 7.3 Printf(“%-10d”, number); To proint an integer left-adjusted in a field of width 10. Example 7.4 Printf(“%010d”, number);

Example 7.5 Printf(“%+10d”, number); Printing Floating-Point Values with a Specified Precision Example 7.6 Printf(“%15.3f”, number);

Example 7.6 Printf(“%15.3f”, number); For strings a format specifier such as %15.3s results in a truncation of the string, and only the first three characters will be printed.

Specifying Variables for Field Width and Precision Printf(“%*d”, width, number); At run time is converted to the symbol * replaced by the variable Printf(“%15d”, number); 7.6 EXAMPLE PROGRAM1

7.7 MORE ON INTERACTIVE INPUT The InputList consists of variable addresses For variables of fundamental data types (such as int, double, and char) we must use the address operator The name of a string is a pointer to the memory location Where the string value is stored

Example 7.13 Scanf(“%4d”, &number); Assign the value 1155 to number.

Example 7.17 The following statement Scanf(“%d %c %lf”, &weight, &response, &height); Will permit us to separate the three values with whitespace. 7.8 EXAMPLE PROGRAM 2: