# Introduction to Computing Lecture 03: Basic input / output operations

Size: px
Start display at page:

Transcription

1 Introduction to Computing Lecture 03: Basic input / output operations Assist.Prof.Dr. Nükhet ÖZBEK Ege University Department of Electrical & Electronics Engineering

2 Topics Streams printf function scanf function

3 Data storage Data can be stored in two different ways: by assignment to a variable copying data from an input device into a variable using a function like scanf

4 Input operation Sometimes, it is need to copy data into a variable for a program to manipulate different data each time it executes This data transfer from the outside world into memory is called an input operation

5 Output operation As the program executes, it performs computations and stores the results in memory These program results can be displayed to the user by an output operation

6 Input/Output Program

7 Input/output functions All input/output operations in C are performed by special program units called input/output functions You can gain access to most of the operations through the preprocessor directive #include <stdio.h>

8 Input/output functions In C, a function call is used to call or activate a function Calling a function is analogous to asking a friend to perform an urgent task

9 Streams Text input or output is dealt with as a sequence of characters A stream serves as a channel to convey characters between I/O and programs

10 Streams: Input -- Example int item; float cost; scanf( %d %f, &item, &cost); _ \n input buffer

11 Streams: Input -- Example (cont) int item; float cost; scanf( %d %f, &item, &cost); _ \n item cost

12 Streams: Input Example (cont) int item; float cost; scanf( %d %f, &item, &cost); _ \n item 135 cost

13 Streams: Input Example (cont) int item; float cost; scanf( %d %f, &item, &cost); _ \n item 135 cost 25.5

14 Streams: Output -- Example printf( Hello!\n ); H e l l o! \n output buffer

15 Streams: Output Example (cont) printf( Hello!\n ); H e l l o! \n

16 Streams: Output Example (cont) printf( Hello!\n ); e l l o! \n H

17 Streams: Output Example (cont) printf( Hello!\n ); l l o! \n He

18 Streams: Output Example (cont) printf( Hello!\n ); l o! \n Hel

19 Streams: Output Example (cont) printf( Hello!\n ); o! \n Hell

20 Streams: Output Example (cont) printf( Hello!\n );! \n Hello

21 Streams: Output Example (cont) printf( Hello!\n ); \n Hello!

22 Streams: Output Example (cont) printf( Hello!\n ); Hello! _

23 Streams From the program's point of view, the characters are queued in a pipe The sequence of characters is organized into lines Each line: can have zero or more characters ends with the "newline" character '\n'

24 "Standard" Streams Standard streams: stdin - standard input usually from keyboard stdout - standard output usually to screen stderr - standard error usually to screen must have at the top of your program #include <stdio.h> can be redirected

25 stdin: Input Data is read in from stdin (into a variable) using the scanf() function

26 Example: ReadData Input name, age, gender, idnumber

27 #include <stdio.h>

28 #include <stdio.h> /*************************************\ Read in important info about a lecturer \**************************************/

29 #include <stdio.h> /*************************************\ Read in important info about a lecturer \**************************************/ int main() { } return 0;

30 #include <stdio.h> /*************************************\ Read in important info about a lecturer \**************************************/ int main() { char name[100]; float age; char gender; int idnumber; return 0; }

31 #include <stdio.h> /*************************************\ Read in important info about a lecturer \**************************************/ int main() { char name[100]; float age; char gender; int idnumber; } scanf("%s %f %c %d", name, &age, &gender, &idnumber); return 0;

32 #include <stdio.h> /*************************************\ Read in important info about a lecturer \**************************************/ int main() { char name[100]; float age; char gender; int idnumber; } scanf("%s %f %c %d", name, &age, &gender, &idnumber); return 0;

33 #include <stdio.h> /*************************************\ Read in important info about a lecturer \**************************************/ int main() { char name[100]; Ali float age; 19.5 char gender; int idnumber; M 2085 scanf("%s %f %c %d", name, &age, &gender, &idnumber); return 0; } Input: Ali 19.5 M 2085

34 stdout:output Data (e.g., from a variable) is written out to stdout using the printf() function.

35 Example: Write Data Set name to Ali Set age to 19.5 Set gender to M Set idnumber to 2085 Output name, age, gender, idnumber

36 #include <stdio.h> /*****************************************\ Write out important info about a lecturer \*****************************************/ int main() { char *name = Ali" ; float age = 19.5; char gender = M'; int idnumber = 2085 ; Ali 19.5 M 2085 _ } printf("%s\n%f\n%c\n%d\n", name, age, gender, idnumber); return 0;

37 Formatted Input and Output General form: printf(format-control-string, other-arguments); scanf(format-control-string, other-arguments ); Examples: printf("%s %f %c %d", name, age, gender, idnumber); scanf("%s %f %c %d", name, &age, &gender, &idnumber);

38 printf -- Format-Control-String Describes the format of the data for output Contains conversion specifiers or place holders and literal characters Example: printf( %s is %d years old.\n, name, age);

39 printf -- Format-Control-String (cont) Describes the format of the data for output Contains conversion specifiers or place holders and literal characters Example: printf( %s is %d years old.\n, name, age); conversion specifiers or placeholders

40 printf -- Format-Control-String (cont) Describes the format of the data for output Contains conversion specifiers and literal characters Example: printf( %s is %d years old.\n, name, age); literal characters

41 printf -- Other-Arguments For printf: variables containing data for output Example: printf( %s is %d years old.\n, name, age); In case of multiple placeholders, number of place holders must match number of variables C matches variables with placeholders in leftto-right order

42 scanf -- Format-Control-String Describes the format of the data given as input Contains conversion specifiers or place holders Example: scanf("%s %f %c %d", name, &age, &gender,&id); conversion specifiers

43 scanf -- Other-Arguments For scanf: pointers to variables in which the input will be stored Example: scanf("%s %f %c %d", name, &age, &gender,&id);

44 scanf -- Other-Arguments (cont) For scanf: pointers to variables in which the input will be stored Example: scanf("%s %f %c %d", name, &age, &gender,&id); Variables of type int, float or char need & Do NOT use & with strings! & is for scanf only!

45 Common Conversion Specifiers for Numerical Information decimal integer: %d printf( What is %d plus %d?\n, x, y); scanf( %d, &sum); float: %f printf( %f squared is...?, x); scanf( %f, &ans); double: printf( %f squared is...?, x); scanf( %lf, &ans);

46 Conversion Specifiers for Alphanumeric Information char: %c printf( What letter follows %c?\n,ch); scanf( %c, &nextchar); string: %s printf( Name: %s\n, name); scanf( %s, name);

47 printf: Conversion Specifiers i or d: display a signed decimal integer f: display a floating point value (default precision is 6) e or E: display a floating point value in exponential notation g or G: display a floating point value in either f form or e form; whichever is more compact for the given value and precision L: placed before any float conversion specifier to indicate that a long double is displayed

48 scanf: Conversion Specifiers d: read an optionally signed decimal integer i: read an optionally signed decimal, octal, or hexadecimal integer i and d: the argument is a pointer to an integer int idnumber; scanf("%d", &idnumber);

49 scanf: Conversion Specifiers (cont) h or l: placed before any integer conversion specifiers to indicate that a short or long integer is to be input long int idnumber; scanf("%ld", &idnumber); l or L: placed before any float conversion specifiers to indicate that a double or long double is to be input

50 Skipping Characters in Input Stream Skipping blank spaces scanf("%d %d %d", &day, &month, &year); An alternative Enter data as dd-mm-yyyy: Store each number in date variables scanf("%d-%d-%d", &day, &month, &year);

51 Displaying Prompts When input data are needed in an interactive program, it is better to use the printf function to display a prompting message or prompt, that tells the user what data to enter and if necessary, the format of the input

52 Displaying Prompts - Examples printf( Enter the distance in miles> ); scanf( %lf, &miles); printf( Enter date as dd-mm-yyyy ); scanf("%d-%d-%d", &day, &month, &year);

53 Formatting output Using justification for decimal numbers int a=15, b=116; printf( %d\n,a); printf( %d,b); Output:

54 Formatting output Using justification for decimal numbers int a=15, b=116; printf( %3d\n,a); printf( %3d,b); Output:

55 Formatting output Floating point numbers double fp = ; printf( "%f %.3f %.2f %e %E\n", fp, fp, fp, fp,fp ); Output: e E+002

56 Formatting output with \n \n is an escape sequence in C The cursor is a moving place market that indicates the next position on the screen where information will be displayed When executing a printf function, the cursor is advanced to the start of the next line on the screen if \n is encountered in the format string

57 \n Examples printf( Here is the first line\n ); printf( \nand this is the second.\n ); Here is the first line and this is the second.

58 \n Examples printf( This sentence appears \non two lines. ); This sentence appears on two lines.

59 Formatting output with \t \t is another escape sequence in C for horizontal tab Example: printf( age id\n ); printf( \n ); printf( %d %d\n,age1,id1); printf( %d %d\n,age2,id2); Output: age id

60 Formatting output with \t Example with (\t and justification): printf( age\tid\n ); printf( ---\t------\n ); printf( %3d\t%4d\n,age1,id1); printf( %3d\t%4d\n,age2,id2); Output: age id

61 Some Other Escape sequences \a: Alert (bell) \b: Backspace \ : Single quotation mark \ : Double quotation mark \\: Backslash

62 Summary Input from keyboard is via the stdin stream using the scanf() function Output to the screen is via the stdout stream using the printf() function Streams carry characters divided into lines with \n character To use the C library functions, you must include the stdio.h header file Input and output can be formatted

### Should you know scanf and printf?

C-LANGUAGE INPUT & OUTPUT C-Language Output with printf Input with scanf and gets_s and Defensive Programming Copyright 2016 Dan McElroy Should you know scanf and printf? scanf is only useful in the C-language,

### ITC213: STRUCTURED PROGRAMMING. Bhaskar Shrestha National College of Computer Studies Tribhuvan University

ITC213: STRUCTURED PROGRAMMING Bhaskar Shrestha National College of Computer Studies Tribhuvan University Lecture 07: Data Input and Output Readings: Chapter 4 Input /Output Operations A program needs

### Unit 4. Input/Output Functions

Unit 4 Input/Output Functions Introduction to Input/Output Input refers to accepting data while output refers to presenting data. Normally the data is accepted from keyboard and is outputted onto the screen.

### C Concepts - I/O. Lecture 19 COP 3014 Fall November 29, 2017

C Concepts - I/O Lecture 19 COP 3014 Fall 2017 November 29, 2017 C vs. C++: Some important differences C has been around since around 1970 (or before) C++ was based on the C language While C is not actually

C How to Program, 6/e 1992-2010 by Pearson Education, Inc. An important part of the solution to any problem is the presentation of the results. In this chapter, we discuss in depth the formatting features

### Fundamentals of Programming

Fundamentals of Programming Lecture 4 Input & Output Lecturer : Ebrahim Jahandar Borrowed from lecturer notes by Omid Jafarinezhad Outline printf scanf putchar getchar getch getche Input and Output in

### Fundamental of Programming (C)

Borrowed from lecturer notes by Omid Jafarinezhad Fundamental of Programming (C) Lecturer: Vahid Khodabakhshi CE 43 - Fall 97 Lecture 4 Input and Output Department of Computer Engineering Outline printf

### CC112 Structured Programming

Arab Academy for Science and Technology and Maritime Transport College of Engineering and Technology Computer Engineering Department CC112 Structured Programming Lecture 3 1 LECTURE 3 Input / output operations

### INTRODUCTION TO C++ C FORMATTED INPUT/OUTPUT. Dept. of Electronic Engineering, NCHU. Original slides are from

INTRODUCTION TO C++ C FORMATTED INPUT/OUTPUT Original slides are from http://sites.google.com/site/progntut/ Dept. of Electronic Engineering, NCHU Outline 2 printf and scanf Streams (input and output)

### printf("%c\n", character); printf("%s\n", "This is a string"); printf("%s\n", string); printf("%s\n",stringptr); return 0;

Chapter 9: Formatted Input/Output ================================= * All input and output is performed with streams - sequences of characters organized into lines. * Each line consists of zero or more

### Copyright The McGraw-Hill Companies, Inc. Permission required for reproduction or display.

Chapter 18 I/O in C Standard C Library I/O commands are not included as part of the C language. Instead, they are part of the Standard C Library. A collection of functions and macros that must be implemented

### Fundamentals of Programming Session 4

Fundamentals of Programming Session 4 Instructor: Reza Entezari-Maleki Email: entezari@ce.sharif.edu 1 Fall 2011 These slides are created using Deitel s slides, ( 1992-2010 by Pearson Education, Inc).

### Fundamentals of Programming. Lecture 3: Introduction to C Programming

Fundamentals of Programming Lecture 3: Introduction to C Programming Instructor: Fatemeh Zamani f_zamani@ce.sharif.edu Sharif University of Technology Computer Engineering Department Outline A Simple C

### The C Programming Language Part 2. (with material from Dr. Bin Ren, William & Mary Computer Science)

The C Programming Language Part 2 (with material from Dr. Bin Ren, William & Mary Computer Science) 1 Overview Input/Output Structures and Arrays 2 Basic I/O character-based putchar (c) output getchar

### CS102: Standard I/O. %<flag(s)><width><precision><size>conversion-code

CS102: Standard I/O Our next topic is standard input and standard output in C. The adjective "standard" when applied to "input" or "output" could be interpreted to mean "default". Typically, standard output

### .. Cal Poly CPE 101: Fundamentals of Computer Science I Alexander Dekhtyar..

.. Cal Poly CPE 101: Fundamentals of Computer Science I Alexander Dekhtyar.. A Simple Program. simple.c: Basics of C /* CPE 101 Fall 2008 */ /* Alex Dekhtyar */ /* A simple program */ /* This is a comment!

### 1/31/2018. Overview. The C Programming Language Part 2. Basic I/O. Basic I/O. Basic I/O. Conversion Characters. Input/Output Structures and Arrays

Overview The C Programming Language Part 2 Input/Output Structures and Arrays (with material from Dr. Bin Ren, William & Mary Computer Science) 1 2 character-based putchar (c) output getchar () input formatted

### CMPT 102 Introduction to Scientific Computer Programming. Input and Output. Your first program

CMPT 102 Introduction to Scientific Computer Programming Input and Output Janice Regan, CMPT 102, Sept. 2006 0 Your first program /* My first C program */ /* make the computer print the string Hello world

### Programming for Engineers Introduction to C

Programming for Engineers Introduction to C ICEN 200 Spring 2018 Prof. Dola Saha 1 Simple Program 2 Comments // Fig. 2.1: fig02_01.c // A first program in C begin with //, indicating that these two lines

### Input/Output Week 5:Lesson 16.1

Input/Output Week 5:Lesson 16.1 Commands (On-Line) scanf/printf Principles of Programming-I / 131101 Prepared by: Dr. Bahjat Qazzaz --------------------------------------------------------------------------------------------

### Formatted Input/Output

Chapter 3 Formatted Input/Output 1 The printf Function The printf function must be supplied with a format string ( 格式化字串 ), followed by any values that are to be inserted into the string during printing:

### C: How to Program. Week /Mar/05

1 C: How to Program Week 2 2007/Mar/05 Chapter 2 - Introduction to C Programming 2 Outline 2.1 Introduction 2.2 A Simple C Program: Printing a Line of Text 2.3 Another Simple C Program: Adding Two Integers

### sends the formatted data to the standard output stream (stdout) int printf ( format_string, argument_1, argument_2,... ) ;

INPUT AND OUTPUT IN C Function: printf() library: sends the formatted data to the standard output stream (stdout) int printf ( format_string, argument_1, argument_2,... ) ; format_string it is

### C Fundamentals & Formatted Input/Output. adopted from KNK C Programming : A Modern Approach

C Fundamentals & Formatted Input/Output adopted from KNK C Programming : A Modern Approach C Fundamentals 2 Program: Printing a Pun The file name doesn t matter, but the.c extension is often required.

### 1/25/2018. ECE 220: Computer Systems & Programming. Write Output Using printf. Use Backslash to Include Special ASCII Characters

University of Illinois at Urbana-Champaign Dept. of Electrical and Computer Engineering ECE 220: Computer Systems & Programming Review: Basic I/O in C Allowing Input from the Keyboard, Output to the Monitor

### Basic Types and Formatted I/O

Basic Types and Formatted I/O C Variables Names (1) Variable Names Names may contain letters, digits and underscores The first character must be a letter or an underscore. the underscore can be used but

### Chapter 2 - Introduction to C Programming

Chapter 2 - Introduction to C Programming 2 Outline 2.1 Introduction 2.2 A Simple C Program: Printing a Line of Text 2.3 Another Simple C Program: Adding Two Integers 2.4 Memory Concepts 2.5 Arithmetic

### Fundamentals of Programming. Lecture 11: C Characters and Strings

1 Fundamentals of Programming Lecture 11: C Characters and Strings Instructor: Fatemeh Zamani f_zamani@ce.sharif.edu Sharif University of Technology Computer Engineering Department The lectures of this

### Fundamental of Programming (C)

Borrowed from lecturer notes by Omid Jafarinezhad Fundamental of Programming (C) Lecturer: Vahid Khodabakhshi Lecture 3 Constants, Variables, Data Types, And Operations Department of Computer Engineering

### CPE 101, reusing/mod slides from a UW course (used by permission) Lecture 5: Input and Output (I/O)

CPE 101, reusing/mod slides from a UW course (used by permission) Lecture 5: Input and Output (I/O) Overview (5) Topics Output: printf Input: scanf Basic format codes More on initializing variables 2000

### BSM540 Basics of C Language

BSM540 Basics of C Language Chapter 3: Data and C Prof. Manar Mohaisen Department of EEC Engineering Review of the Precedent Lecture Explained the structure of a simple C program Introduced comments in

1 29 Formatted Output 2 OBJECTIVES In this chapter you will learn: To understand input and output streams. To use printf formatting. To print with field widths and precisions. To use formatting flags in

### Introduction to C Programming. Chih-Wei Tang ( 唐之瑋 ) Department of Communication Engineering National Central University JhongLi, Taiwan

Introduction to C Programming Chih-Wei Tang ( 唐之瑋 ) Department of Communication Engineering National Central University JhongLi, Taiwan Outline Printing texts Adding 2 integers Comparing 2 integers C.E.,

Introductory Medical Device Prototyping Advanced C Programming Topics, http://saliterman.umn.edu/ Department of Biomedical Engineering, University of Minnesota Operations on Bits 1. Recall there are 8

### Computer Programming Lecture 12 Pointers

Computer Programming Lecture 2 Pointers Assist.Prof.Dr. Nükhet ÖZBEK Ege University Department of Electrical & Electronics Engineering nukhet.ozbek@ege.edu.tr Topics Introduction to Pointers Pointers and

### UNIT - I. Introduction to C Programming. BY A. Vijay Bharath

UNIT - I Introduction to C Programming Introduction to C C was originally developed in the year 1970s by Dennis Ritchie at Bell Laboratories, Inc. C is a general-purpose programming language. It has been

### EC 413 Computer Organization

EC 413 Computer Organization C/C++ Language Review Prof. Michel A. Kinsy Programming Languages There are many programming languages available: Pascal, C, C++, Java, Ada, Perl and Python All of these languages

### Lecture 4. Console input/output operations. 1. I/O functions for characters 2. I/O functions for strings 3. I/O operations with data formatting

Lecture 4 Console input/output operations 1. I/O functions for characters 2. I/O functions for strings 3. I/O operations with data formatting Header files: stdio.h conio.h C input/output revolves around

### c) Comments do not cause any machine language object code to be generated. d) Lengthy comments can cause poor execution-time performance.

2.1 Introduction (No questions.) 2.2 A Simple Program: Printing a Line of Text 2.1 Which of the following must every C program have? (a) main (b) #include (c) /* (d) 2.2 Every statement in C

### AWK - PRETTY PRINTING

AWK - PRETTY PRINTING http://www.tutorialspoint.com/awk/awk_pretty_printing.htm Copyright tutorialspoint.com So far we have used AWK's print and printf functions to display data on standard output. But

### C Programming

204216 -- C Programming Chapter 3 Processing and Interactive Input Adapted/Assembled for 204216 by Areerat Trongratsameethong A First Book of ANSI C, Fourth Edition Objectives Assignment Mathematical Library

### Muntaser Abulafi Yacoub Sabatin Omar Qaraeen. C Data Types

Programming Fundamentals for Engineers 0702113 5. Basic Data Types Muntaser Abulafi Yacoub Sabatin Omar Qaraeen 1 2 C Data Types Variable definition C has a concept of 'data types' which are used to define

### BSM540 Basics of C Language

BSM540 Basics of C Language Chapter 4: Character strings & formatted I/O Prof. Manar Mohaisen Department of EEC Engineering Review of the Precedent Lecture To explain the input/output functions printf()

### Overview of C, Part 2. CSE 130: Introduction to Programming in C Stony Brook University

Overview of C, Part 2 CSE 130: Introduction to Programming in C Stony Brook University Integer Arithmetic in C Addition, subtraction, and multiplication work as you would expect Division (/) returns the

### Stream Model of I/O. Basic I/O in C

Stream Model of I/O 1 A stream provides a connection between the process that initializes it and an object, such as a file, which may be viewed as a sequence of data. In the simplest view, a stream object

### 11 Console Input/Output

11 Console Input/Output Types of I/O Console I/O Functions Formatted Console I/O Functions sprintf( ) and sscanf( ) Functions Unformatted Console I/O Functions Summary Exercise 1 As mentioned in the first

### Features of C. Portable Procedural / Modular Structured Language Statically typed Middle level language

1 History C is a general-purpose, high-level language that was originally developed by Dennis M. Ritchie to develop the UNIX operating system at Bell Labs. C was originally first implemented on the DEC

### Chapter 2: Overview of C. Problem Solving & Program Design in C

Chapter 2: Overview of C Problem Solving & Program Design in C Addison Wesley is an imprint of Why Learn C? Compact, fast, and powerful High-level Language Standard for program development (wide acceptance)

### The C language. Introductory course #1

The C language Introductory course #1 History of C Born at AT&T Bell Laboratory of USA in 1972. Written by Dennis Ritchie C language was created for designing the UNIX operating system Quickly adopted

### Standard I/O in C and C++

Introduction to Computer and Program Design Lesson 7 Standard I/O in C and C++ James C.C. Cheng Department of Computer Science National Chiao Tung University Standard I/O in C There three I/O memory buffers

### 211: Computer Architecture Summer 2016

211: Computer Architecture Summer 2016 Liu Liu Topic: C Programming Data Representation I/O: - (example) cprintf.c Memory: - memory address - stack / heap / constant space - basic data layout Pointer:

### UNIT-I Input/ Output functions and other library functions

Input and Output functions UNIT-I Input/ Output functions and other library functions All the input/output operations are carried out through function calls. There exists several functions that become

### ME 172. Lecture 2. Data Types and Modifier 3/7/2011. variables scanf() printf() Basic data types are. Modifiers. char int float double

ME 172 Lecture 2 variables scanf() printf() 07/03/2011 ME 172 1 Data Types and Modifier Basic data types are char int float double Modifiers signed unsigned short Long 07/03/2011 ME 172 2 1 Data Types

### Work relative to other classes

Work relative to other classes 1 Hours/week on projects 2 C BOOTCAMP DAY 1 CS3600, Northeastern University Slides adapted from Anandha Gopalan s CS132 course at Univ. of Pittsburgh Overview C: A language

### C Input/Output. Before we discuss I/O in C, let's review how C++ I/O works. int i; double x;

C Input/Output Before we discuss I/O in C, let's review how C++ I/O works. int i; double x; cin >> i; cin >> x; cout

### Reserved Words and Identifiers

1 Programming in C Reserved Words and Identifiers Reserved word Word that has a specific meaning in C Ex: int, return Identifier Word used to name and refer to a data element or object manipulated by the

### Fundamentals of C. Structure of a C Program

Fundamentals of C Structure of a C Program 1 Our First Simple Program Comments - Different Modes 2 Comments - Rules Preprocessor Directives Preprocessor directives start with # e.g. #include copies a file

### BİL200 TUTORIAL-EXERCISES Objective:

Objective: The purpose of this tutorial is learning the usage of -preprocessors -header files -printf(), scanf(), gets() functions -logic operators and conditional cases A preprocessor is a program that

### EE458 - Embedded Systems Lecture 4 Embedded Devel.

EE458 - Embedded Lecture 4 Embedded Devel. Outline C File Streams References RTC: Chapter 2 File Streams man pages 1 Cross-platform Development Environment 2 Software available on the host system typically

### Input / Output Functions

CSE 2421: Systems I Low-Level Programming and Computer Organization Input / Output Functions Presentation G Read/Study: Reek Chapter 15 Gojko Babić 10-03-2018 Input and Output Functions The stdio.h contain

### Number Systems, Scalar Types, and Input and Output

Number Systems, Scalar Types, and Input and Output Outline: Binary, Octal, Hexadecimal, and Decimal Numbers Character Set Comments Declaration Data Types and Constants Integral Data Types Floating-Point

### Week 3 More Formatted Input/Output; Arithmetic and Assignment Operators

Week 3 More Formatted Input/Output; Arithmetic and Assignment Operators Formatted Input and Output The printf function The scanf function Arithmetic and Assignment Operators Simple Assignment Side Effect

### Outline. Computer Programming. Preprocessing in C. File inclusion. Preprocessing in C

Outline Computer Programming The greatest gift you can give another is the purity of your attention. Richard Moss Preprocessing in C Function vs macro Conditional compilation Constant identifiers Standard

### Chapter 2 THE STRUCTURE OF C LANGUAGE

Lecture # 5 Chapter 2 THE STRUCTURE OF C LANGUAGE 1 Compiled by SIA CHEE KIONG DEPARTMENT OF MATERIAL AND DESIGN ENGINEERING FACULTY OF MECHANICAL AND MANUFACTURING ENGINEERING Contents Introduction to

### ANSI C Programming Simple Programs

ANSI C Programming Simple Programs /* This program computes the distance between two points */ #include #include #include main() { /* Declare and initialize variables */ double

### CSCI 2132: Software Development. Norbert Zeh. Faculty of Computer Science Dalhousie University. Introduction to C. Winter 2019

CSCI 2132: Software Development Introduction to C Norbert Zeh Faculty of Computer Science Dalhousie University Winter 2019 The C Programming Language Originally invented for writing OS and other system

### The Design of C: A Rational Reconstruction (cont.)

The Design of C: A Rational Reconstruction (cont.) 1 Goals of this Lecture Recall from last lecture Help you learn about: The decisions that were available to the designers of C The decisions that were

### LESSON 4. The DATA TYPE char

LESSON 4 This lesson introduces some of the basic ideas involved in character processing. The lesson discusses how characters are stored and manipulated by the C language, how characters can be treated

### CS113: Lecture 7. Topics: The C Preprocessor. I/O, Streams, Files

CS113: Lecture 7 Topics: The C Preprocessor I/O, Streams, Files 1 Remember the name: Pre-processor Most commonly used features: #include, #define. Think of the preprocessor as processing the file so as

### Standard C Library Functions

Demo lecture slides Although I will not usually give slides for demo lectures, the first two demo lectures involve practice with things which you should really know from G51PRG Since I covered much of

### Gabriel Hugh Elkaim Spring CMPE 013/L: C Programming. CMPE 013/L: C Programming

1 Literal Constants Definition A literal or a literal constant is a value, such as a number, character or string, which may be assigned to a variable or a constant. It may also be used directly as a function

### Chapter 9 Strings. With this array declaration: char s[10];

Chapter 9 Strings 9.1 Chapter Overview There is no data type in C called ʻstringʼ; instead, strings are represented by an array of characters. There is an assortment of useful functions for strings that

### Differentiate Between Keywords and Identifiers

History of C? Why we use C programming language Martin Richards developed a high-level computer language called BCPL in the year 1967. The intention was to develop a language for writing an operating system(os)

### Lecture 3. More About C

Copyright 1996 David R. Hanson Computer Science 126, Fall 1996 3-1 Lecture 3. More About C Programming languages have their lingo Programming language Types are categories of values int, float, char Constants

### Introduction to the C Programming Language

Introduction to the C Programming Language Michael Griffiths Corporate Information and Computing Services The University of Sheffield Email m.griffiths@sheffield.ac.uk Course Outline Part 1 Introduction

### Full file at C How to Program, 6/e Multiple Choice Test Bank

2.1 Introduction 2.2 A Simple Program: Printing a Line of Text 2.1 Lines beginning with let the computer know that the rest of the line is a comment. (a) /* (b) ** (c) REM (d)

### C++ Basics. Lecture 2 COP 3014 Spring January 8, 2018

C++ Basics Lecture 2 COP 3014 Spring 2018 January 8, 2018 Structure of a C++ Program Sequence of statements, typically grouped into functions. function: a subprogram. a section of a program performing

### Intro to Computer Programming (ICP) Rab Nawaz Jadoon

Intro to Computer Programming (ICP) Rab Nawaz Jadoon DCS COMSATS Institute of Information Technology Assistant Professor COMSATS IIT, Abbottabad Pakistan Introduction to Computer Programming (ICP) What

### Binghamton University. CS-220 Spring Includes & Streams

Includes & Streams 1 C Pre-Processor C Program Pre-Processor Pre-processed C Program Header Files Header Files 2 #include Two flavors: #include Replace this line with the contents of file abc.h

### DECLARATIONS. Character Set, Keywords, Identifiers, Constants, Variables. Designed by Parul Khurana, LIECA.

DECLARATIONS Character Set, Keywords, Identifiers, Constants, Variables Character Set C uses the uppercase letters A to Z. C uses the lowercase letters a to z. C uses digits 0 to 9. C uses certain Special

### A Fast Review of C Essentials Part I

A Fast Review of C Essentials Part I Structural Programming by Z. Cihan TAYSI Outline Program development C Essentials Functions Variables & constants Names Formatting Comments Preprocessor Data types

### CSC 1107: Structured Programming

CSC 1107: Structured Programming J. Kizito Makerere University e-mail: www: materials: e-learning environment: office: alt. office: jkizito@cis.mak.ac.ug http://serval.ug/~jona http://serval.ug/~jona/materials/csc1107

### UNIT IV-2. The I/O library functions can be classified into two broad categories:

UNIT IV-2 6.0 INTRODUCTION Reading, processing and writing of data are the three essential functions of a computer program. Most programs take some data as input and display the processed data, often known

### C - Basic Introduction

C - Basic Introduction C is a general-purpose high level language that was originally developed by Dennis Ritchie for the UNIX operating system. It was first implemented on the Digital Equipment Corporation

### Operators and Control Flow. CS449 Fall 2017

Operators and Control Flow CS449 Fall 2017 Running Example #include /* header file */ int main() { int grade, count, total, average; /* declaramons */ count = 0; /* inimalizamon */ total = 0;

### Goals of C "" The Goals of C (cont.) "" Goals of this Lecture"" The Design of C: A Rational Reconstruction"

Goals of this Lecture The Design of C: A Rational Reconstruction Help you learn about: The decisions that were available to the designers of C The decisions that were made by the designers of C Why? Learning

### CSE 12 Spring 2016 Week One, Lecture Two

CSE 12 Spring 2016 Week One, Lecture Two Homework One and Two: hw2: Discuss in section today - Introduction to C - Review of basic programming principles - Building from fgetc and fputc - Input and output

### Unit 1: Introduction to C Language. Saurabh Khatri Lecturer Department of Computer Technology VIT, Pune

Unit 1: Introduction to C Language Saurabh Khatri Lecturer Department of Computer Technology VIT, Pune Introduction to C Language The C programming language was designed by Dennis Ritchie at Bell Laboratories

### Standard File Pointers

1 Programming in C Standard File Pointers Assigned to console unless redirected Standard input = stdin Used by scan function Can be redirected: cmd < input-file Standard output = stdout Used by printf

### Worksheet 4 Basic Input functions and Mathematical Operators

Name: Student ID: Date: Worksheet 4 Basic Input functions and Mathematical Operators Objectives After completing this worksheet, you should be able to Use an input function in C Declare variables with

### 1. What type of error produces incorrect results but does not prevent the program from running? a. syntax b. logic c. grammatical d.

Gaddis: Starting Out with Python, 2e - Test Bank Chapter Two MULTIPLE CHOICE 1. What type of error produces incorrect results but does not prevent the program from running? a. syntax b. logic c. grammatical

### Applied Programming and Computer Science, DD2325/appcs15 PODF, Programmering och datalogi för fysiker, DA7011

Applied Programming and Computer Science, DD2325/appcs15 PODF, Programmering och datalogi för fysiker, DA7011 Autumn 2015 Lecture 3, Simple C programming M. Eriksson (with contributions from A. Maki and

### Introduction to Programming

Introduction to Programming Lecture 5: Interaction Interaction Produce output Get input values 2 Interaction Produce output Get input values 3 Printing Printing messages printf("this is message \n"); Printing

### CpSc 1111 Lab 4 Part a Flow Control, Branching, and Formatting

CpSc 1111 Lab 4 Part a Flow Control, Branching, and Formatting Your factors.c and multtable.c files are due by Wednesday, 11:59 pm, to be submitted on the SoC handin page at http://handin.cs.clemson.edu.

### 3. Types of Algorithmic and Program Instructions

3. Types of Algorithmic and Program Instructions Objectives 1. Introduce programming language concepts of variables, constants and their data types 2. Introduce types of algorithmic and program instructions

### Friday, September 16, Lab Notes. Command line arguments More pre-processor options Programs: Finish Program 1, begin Program 2 due next week

Friday, September 16, 2016 Lab Notes Topics for today Redirection of input and output Command line arguments More pre-processor options Programs: Finish Program 1, begin Program 2 due next week 1. Redirection