A simple C program: Printing a line of text #include main() { printf(“hello, world\n”); } Program output: hello, world.

Slides:



Advertisements
Similar presentations
Dale Roberts Basic I/O – printf() CSCI 230 Department of Computer and Information Science, School of Science, IUPUI Dale Roberts, Lecturer Department of.
Advertisements

Imperative Programming Prof. Béat Hirsbrunner Amine Tafat, PhD Student Matthias Buchs and Raphaël Lesceux, Graduate Students Department of Informatics.
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.
C programming an Introduction. Types There are only a few basic data types in C. char a character int an integer, in the range -32,767 to 32,767 long.
 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.
1 CSE1301 Computer Programming Lecture 5: Components of a C Program (Part 1)
Basic Input/Output and Variables Ethan Cerami New York
Programming in C #2 Input / Output.
Introduction to C Language
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.
Basic Input - Output. Output functions  printf() – is a library function that displays information on-screen. The statement can display a simple text.
 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. 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
Introduction to “Programming in C”
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.
EPSII 59:006 Spring Introduction In this lecture  Formatted Input/Output scanf and printf  Streams (input and output) gets, puts, getchar, putchar.
Programming I Introduction Introduction The only way to learn a new programming language is by writing programs in it. The first program to.
1 CSE1301 Computer Programming Lecture 5: Components of a C Program (Part 1) Linda M c Iver.
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.
Introduction to C Programming Chapter 2 : Data Input, Processing and Output.
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.
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.
CSC141 Introduction to Computer Programming Teacher: AHMED MUMTAZ MUSTEHSAN Lecture - 6.
CSE1301 Computer Programming: Lecture 6 Input/Output.
Introduction to Computer Organization & Systems Topics: Types in C: floating point COMP C Part III.
1 Homework Done the reading? –K&R –Glass Chapters 1 and 2 Applied for cs240? (If not, keep at it!) Gotten a UNIX account? (If not, keep at it!)
© Janice Regan, CMPT 102, Sept CMPT 102 Introduction to Scientific Computer Programming Input and Output.
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"
Computer Programming A simple example /* HelloWorld: A simple C program */ #include int main (void) { printf (“Hello world!\n”); return.
 2007 Pearson Education, Inc. All rights reserved. A Simple C Program 1 /* ************************************************* *** Program: hello_world.
Review (before the 1 st test): while (conditions) { statements; } while loop: if/else if/else statements: if (conditions) { statements; } else if (different.
CSCI 130 Basic Input and Output Chapter 9. The printf ( ) function Printf(“\nThe value of x is %d”, x); Displayed to screen (assume x = 12): –The value.
C is a high level language (HLL)
Introduction to Programming Lecture 5: Interaction.
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.
BIL 104E Introduction to Scientific and Engineering Computing Lecture 2.
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.
From Algorithms to Programs Both are sets of instructions on how to do a task Algorithm: –talking to humans, easy to understand –in plain (English) language.
C language--Introduction. History 1970: B by Ken Thompson at AT&T Bell Lab 1972: C by Dennis Ritchie and Ken Tompson at At&T Bell Lab for UNIX 1978: “The.
Introduction to Computing Lecture 03: Basic input / output operations Introduction to Computing Lecture 03: Basic input / output operations Assist.Prof.Dr.
CSCE 206 Structured Programming in C
Formatted Input and Output
INC 161 , CPE 100 Computer Programming
INTRODUCTION Every language has some features that provides interaction between the program and the user of the program. C language uses the reference.
Input & Output Operations
Introduction to C CSE 2031 Fall /3/ :33 AM.
OUTPUT STATEMENTS GC 201.
Programming in C Input / Output.
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.
Programming in C 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
מ- C++ ל- C קרן כליף.
CSC215 Homework Homework 02 Due date: Sep 30, 2016.
Programming in C Input / Output.
Introduction to C EECS May 2019.
Introduction to C CSE 2031 Fall /15/2019 8:26 AM.
Presentation transcript:

A simple C program: Printing a line of text #include main() { printf(“hello, world\n”); } Program output: hello, world

More C programs #include main() { printf(“My first program.\n”); printf(“It is wonderful.”); } Program output: My first program. It is wonderful.

More C programs #include main() { printf(“My first program.”); printf(“It is wonderful.”); } Program output: My first program.It is wonderful.

Printing characters Source program: printf(“Welcome\nto\nCOMP 1180!\n”); Program output: Welcome to COMP 1180! You can use printf to print a string of characters; but there are special cases: For double quote, use \” For single quote, use \’ For backslash, use \\ For newline, use \n

Formatted Output (integer,float,char,string) Almost every C program start with the following: #include for the access to the standard input/output library For the “printf” statement: printf(format-string, arg1, arg2,...); Format-string tells the program how to print the arguments out Format-string contains two types of objects: ordinary characters and conversion specifications Each conversion specification begins with a % and ends with a conversion character and maybe have a minus sign, a number, and a period in between

Basic Printf Conversions %d%iinteger %ooctal (Base 8) %x%Xhexadecimal (Base 16) %ffloating point %e%Efloating point (exponent) %g%Gfloating point (general format) %csingle character %scharacter string %print a %

Examples on Formatted Printf Statements int a = 5; int b = 10; printf(“%d\n”, a);5 printf(“%5d\n”, a); 5 printf(“%5d\n”, b); 10 printf(“%d %d\n”, a, b);5 10 printf(“a = %d b = %3d\n”, a, b);a = 5 b = 10 float x = ; printf(“%f\n”, x); printf(“%e\n”, x); e+01 printf(“%8.3f\n”, x); x = ; printf(“%e\n”, x); e-01

More Examples on Printf (strings) printf(“%s”, “hello, world”);hello, world: printf(“%10s”, “hello, world”);hello, world: printf(“%.10s”, “hello, world”);hello, wor: printf(“%-10s”, “hello, world”);hello, world: printf(“%.15s”, “hello, world”);hello, world: printf(“%-15s”, “hello, world”);hello, world : printf(“%15.10s”, “hello, world”); hello, wor: printf(“%-15.10s”, “hello, world”);hello, wor :

Formatted Input For “scanf” statements, scanf(format-string, addr1, addr2,...); Examples: float f; int lower, upper; char ch; scanf(“%f”, &fahr); scanf(“%d%d”, &lower, &upper); scanf(“%c”, ch); ch = getchar(); get the next character from STDIN putchar(ch); put the character to STDOUT