Department of Electronic & Electrical Engineering IO reading and writing variables scanf printf format strings "%d %c %f"

Slides:



Advertisements
Similar presentations
Introduction to C Systems Programming Concepts. Introduction to C A simple C Program A simple C Program –Variable Declarations –printf ( ) Compiling and.
Advertisements

Strings Input/Output scanf and printf sscanf and sprintf gets and puts.
Single Variable and a Lot of Variables The declaration int k; float f; reserve one single integer variable called k and one single floating point variable.
What is a pointer? First of all, it is a variable, just like other variables you studied So it has type, storage etc. Difference: it can only store the.
C Programming. printf int printf ( const char * format,... ); printf ("Characters: %c \n", 'a'); printf ("Decimals: %d %f\n", 1977, 3.14); specifierOutputExample.
By Senem Kumova Metin 1 POINTERS + ARRAYS + STRINGS REVIEW.
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.
Basic C Programming Data Types and Arithmetic Operations 01/30/15.
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.
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:
Lecture No: 16. The scanf() function In C programming language, the scanf() function is used to read information from standard input device (keyboard).
Input/Output  Input/Output operations are performed using input/output functions  Common input/output functions are provided as part of C’s standard.
© 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 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.
C And C Based IO. C C = portable assembly language Developed 1972 w/Unix – Systems focus.
STRING Dong-Chul Kim BioMeCIS UTA 10/7/
1 計算機程式設計 Introduction to Computer Programming Lecture01: Introduction and Hello World 9/10/2012 Slides modified from Yin Lou, Cornell CS2022: Introduction.
Algorithm and Programming Array Dr. Ir. Riri Fitri Sari MM MSc International Class Electrical Engineering Dept University of Indonesia 15 March 2009.
C Programming Lecture 10 Instructor: Wen, Chih-Yu Department of Electrical Engineering National Chung Hsing University.
Chapter 7 Formatted input and output. 7.1 introduction Tax: This result is correct; but it would be better Maybe as $13, Make formatting.
Chapter 3: Formatted Input/Output Copyright © 2008 W. W. Norton & Company. All rights reserved. 1 Chapter 3 Formatted Input/Output.
1 ร. ศ. ดร. สุเทพ มาดารัศมี Understanding Pointers in C Chapter 10 of Programming with C Book.
Variables When programming it is often necessary to store a value for use later on in the program. A variable is a label given to a location in memory.
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.
CSE1301 Computer Programming: Lecture 6 Input/Output.
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 Types and Memory Addresses Pointers & and * operators.
Department of Electronic & Electrical Engineering Lecture 3 IO reading and writing variables scanf printf format strings "%d %c %f" Expressions operators.
Introduction to Programming Lecture 5: Interaction.
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 3: Formatted Input/Output 1 Chapter 3 Formatted Input/Output.
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.
Formatted Input and Output
User Interaction and Variables
ECE Application Programming
Formatted Input/Output
INC 161 , CPE 100 Computer Programming
Jonathan C.L. Liu, Ph.D. CISE Department University of Florida, USA
Input/output.
Chapter 3: I/O Management
CSCI206 - Computer Organization & Programming
Formatted Input/Output
Basic notes on pointers in C
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.
CSI 121 Structured Programming Language Lecture 7: Input/Output
توابع ورودي-خروجي.
I/O in C Lecture 6 Winter Quarter Engineering H192 Winter 2005
IPC144 Introduction to Programming Using C Week 8 – Lesson 1
Strings and Pointer Arrays
EECE.2160 ECE Application Programming
EECE.2160 ECE Application Programming
C Programming Pointers
EECE.2160 ECE Application Programming
EECE.2160 ECE Application Programming
EECE.2160 ECE Application Programming
EECE.2160 ECE Application Programming
EECE.2160 ECE Application Programming
Getting Started With Coding
Presentation transcript:

Department of Electronic & Electrical Engineering IO reading and writing variables scanf printf format strings "%d %c %f"

Department of Electronic & Electrical Engineering Reading data... Simple IO... scanf #include { int x; scanf("%d",&x); } "%d" is a control string %d is a slot for an integer & is the address of operator &x is the memory location to place the integer (where x is stored). scanf("%d",x); common mistake

Department of Electronic & Electrical Engineering Format string (scanf) common slots

Department of Electronic & Electrical Engineering scanf ---- WARNING --- scanf can be confusing to use especially if you do not enter your data correctly. scanf reads your input until it has filled all the slots (%s). If you have extra input characters that are not read by a scanf they will be read by the next scanf !

Department of Electronic & Electrical Engineering Writing data ( printf ) Similar to scanf but additional formatting options %f --- float e.g 34.1 %e --- with exponent 3.41e1 %d --- decimal (for int type) %c --- single character %s --- string (array of char) %p --- address / pointer We can also do: %10.4f --- print at least 10 characters (maybe spaces) with 4 digits after the decimal point.

Department of Electronic & Electrical Engineering Example using scanf float x,y; char c; scanf("%f %c %f",&x,&c,&y); printf("%f %c %f",x,c,y); There is a slot for each parameter The number and type of parameters must match the slots

Department of Electronic & Electrical Engineering DEMO: IO Dr Leonard writes a program to read in some numbers and print a result. Illustrating the use of scanf and printf.