Engineering Computing I Chapter 1 – Part B A Tutorial Introduction continued.

Slides:



Advertisements
Similar presentations
Character Arrays (Single-Dimensional Arrays) A char data type is needed to hold a single character. To store a string we have to use a single-dimensional.
Advertisements

Introduction to C Programming
ARDUINO CLUB Session 1: C & An Introduction to Linux.
Lectures 10 & 11.
C Characters & Strings Character Review Character Handling Library Initialization String Conversion Functions String Handling Library Standard Input/Output.
1 Chapter 10 Strings and Pointers. 2 Introduction  String Constant  Example: printf(“Hello”); “Hello” : a string constant oA string constant is a series.
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.
 2000 Prentice Hall, Inc. All rights reserved Fundamentals of Strings and Characters String declarations –Declare as a character array or a variable.
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 122 – Data Structures Characters and Strings.
 C++ programming facilitates a disciplined approach to program design. ◦ If you learn the correct way, you will be spared a lot of work and frustration.
1 Homework Assignments Turn in HW1 (If not done yet, catch up!) Questions about HW1? Anyone still stuck on apply / UNIX account? Everyone have the books?
Software Development Method. Assignments Due – Homework 0, Warmup Reading – Chapter 2 –
Character Input and Output C and Data Structures Baojian Hua
1 Lecture 2  Input-Process-Output  The Hello-world program  A Feet-to-inches program  Variables, expressions, assignments & initialization  printf()
1 9/1/06CS150 Introduction to Computer Science 1 What Data Do We Have? CS 150 Introduction to Computer Science I.
Imperative Programming Prof. Béat Hirsbrunner Amine Tafat, PhD Student Matthias Buchs and Raphaël Lesceux, Graduate Students Department of Informatics.
0 Arrays (1/2) #include /* count digits, white space, others */ main() { int c, i, nwhite, nother; int ndigit[10]; nwhite = nother = 0; for (i = 0; i
Functions / Procedures
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 6P. 1Winter Quarter I/O in C Lecture 6.
Character Input and Output
Basic Input/Output and Variables Ethan Cerami New York
C Programming Strings. Array of characters – most common type of array in C  Let’s make them easier for use Denote the end of array using a special character.
Chapter 3: Introduction to C Programming Language C development environment A simple program example Characters and tokens Structure of a C program –comment.
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.
Chapter 5: Data Input and Output Department of Computer Science Foundation Year Program Umm Alqura University, Makkah Computer Programming Skills
CNG 140 C Programming (Lecture set 9) Spring Chapter 9 Character Strings.
 2000 Prentice Hall, Inc. All rights reserved. Chapter 8 - Characters and Strings Outline 8.1Introduction 8.2Fundamentals of Strings and Characters 8.3Character.
STRINGS & STRING HANDLING FUNCTIONS STRINGS & STRING HANDLING FUNCTIONS.
Programming I Introduction Introduction The only way to learn a new programming language is by writing programs in it. The first program to.
1 Lab Session-8 CSIT-121 Spring 2005 Call by Reference Lab Exercise for Demo Practice Problems.
Outline Symbolic Constants Character Input and Output if … else switch…case.
Programming Language  C Tutorial Introduction 主講人:虞台文.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 5 – Dental Payment Application: Introducing.
CMPSC 16 Problem Solving with Computers I Spring 2014 Instructor: Tevfik Bultan Lecture 12: Pointers continued, C strings.
An Introduction to Java Programming and Object-Oriented Application Development Chapter 7 Characters, Strings, and Formatting.
CHAPTER 7 DATA INPUT OUTPUT Prepared by: Lec. Ghader R. Kurdi.
File IO and command line input CSE 2451 Rong Shi.
Chapter 05 (Part III) Control Statements: Part II.
Chapter-4 Managing input and Output operation.  Reading, processing and writing of data are three essential functions of a computer program.  Most programs.
Representing Strings and String I/O. Introduction A string is a sequence of characters and is treated as a single data item. A string constant, also termed.
C++ Programming Lecture 7 Control Structure I (Selection) – Part II The Hashemite University Computer Engineering Department.
Prof. Béat Hirsbrunner Ammar Halabi, PhD student (exercises) Dani Rotzetter, Master student (exercises) Bachelor students : Major in computer science (3rd.
CS 261 C Basics Page 2 1/14/2016 CS 261, WSU Vancouver Primitive Types Notes: 4 A is a constant; B is a variable.
C++ STRINGS ● string is part of the Standard C++ Library ● new stuff: ● cin : standard input stream (normally the keyboard) of type istream. ● >> operator.
An Array Type For Strings. Two ways to represent strings – i.e. “Hello” cstring An array with base type char Older way of processing strings Null character.
An Introduction to Programming with C++ Sixth Edition Chapter 13 Strings.
Dale Roberts Department of Computer and Information Science, School of Science, IUPUI CSCI N305 Characters and Strings Functions.
Engineering Computing I Chapter 5 Pointers and Arrays.
CS 1704 Introduction to Data Structures and Software Engineering.
Midterm Review Tami Meredith. Primitive Data Types byte, short, int, long Values without a decimal point,..., -1, 0, 1, 2,... float, double Values with.
A First Book of ANSI C Fourth Edition Chapter 9 Character Strings.
CCSA 221 Programming in C INPUT AND OUTPUT OPERATIONS IN C – PART 1 1.
D. Gotseva PL - Lectures 1 Programming Languages Lectures Assoc. Prof. PhD Daniela Gotseva
CCSA 221 Programming in C CHAPTER 3 COMPILING AND RUNNING YOUR FIRST PROGRAM 1 ALHANOUF ALAMR.
Chapter 4 Strings and Screen I/O. Objectives Define strings and literals. Explain classes and objects. Use the string class to store strings. Perform.
1 Chapter 8 – Character Arrays and Strings Outline 8.1Introduction 8.2Declaring and Initializing String 8.3Input/output of strings 8.4String-handling Functions.
Chapter 2 Introduction to C++ Programming
Chapter 7 Text Input/Output Objectives
Chapter 7 Text Input/Output Objectives
Getting Started with C.
A First Book of ANSI C Fourth Edition
Some Basics for Problem Analysis and Solutions
Structured Programming (Top Down Step Refinement)
I/O in C Lecture 6 Winter Quarter Engineering H192 Winter 2005
Your questions from last session
Engineering Problem Solving with C++ An Object Based Approach
Engineering Problem Solving with C++ An Object Based Approach
C++ Programming Lecture 7 Control Structure I (Selection) – Part II
Introduction to Computer Science
Presentation transcript:

Engineering Computing I Chapter 1 – Part B A Tutorial Introduction continued

Character Input and Output c = getchar(); Variable ‘c’ reads the next input character from a text stream Chapter 1 - Part BSpring 20112

File Copying Chapter 1 - Part BSpring 20113

File Copying Compact Form The parentheses around the assignment, within the condition are necessary! c = getchar() != EOFc = (getchar() != EOF)  Chapter 1 - Part BSpring 20114

Exercises Exercise 1-6. Verify that the expression getchar() != EOF is 0 or 1 Exercise 1-7. Write a program to print the value of EOF Chapter 1 - Part BSpring 20115

Character Counting Auto-increment Equivalent to: nc = nc +1; Chapter 1 - Part BSpring 20116

Line Counting Chapter 1 - Part BSpring 20117

Exercise Spring 2011Chapter 1 - Part B8 Write a program named BlankCounting.c to count blanks.

Word Counting Pseudo Code  Initialize – State = OUT /* start assuming not within a word */ – nc = nl = nw = 0 /* all counters are cleared*/  while (c= character) != EOF  { – ++nc – if c== \nl ++nl – if c is a white character – i.e. ‘ ‘, ‘\n’ or ‘\t’ State = OUT /* start of the none white character will create a word */ – else if State == OUT State = IN ++nw  } State nc nl nw c Chapter 1 - Part BSpring 20119

Word Counting Chapter 1 - Part BSpring

1.6 Arrays write a program to count the number of occurrences of each digit, of white space characters (blank, tab, newline), and of all other characters Chapter 1 - Part BSpring

Exercise Write a program to count the number of occurrences of all “vowels”, i.e. ‘a’, ‘e’, ‘i’, ‘o’ and ‘u’. Use an array of counters. Chapter 1 - Part BSpring

 A function provides a convenient way to encapsulate some computation, which can then be used without worrying about its implementation.  With properly designed functions, it is possible to ignore how a job is done; knowing what is done is sufficient.  functions like printf, getchar and putchar have been supplied by C Library  Write the function power(m,n) to raise an integer m to a positive integer power n. That is, the value of power(2,5) is 32 Chapter 1 - Part BSpring

function power(m,n) A function definition has this form: return-type function-name(parameter declarations, if any) { declarations Statements return expression; } Chapter 1 - Part BSpring

How to Call a Function Chapter 1 - Part BSpring

1.9 Character Arrays  The most common type of array in C is the array of characters  write a program that reads a set of text lines and prints the longest Chapter 1 - Part BSpring

Chapter 1 - Part BSpring

getline: read a line into s, return length Chapter 1 - Part BSpring

Copy : copy ’from’ into ’to’; assume ‘to’ is big enough Chapter 1 - Part BSpring

How Strings Are Stored! "hello\n" Chapter 1 - Part BSpring