Characters and Strings

Slides:



Advertisements
Similar presentations
Lecture 9: Character and String
Advertisements

EC-111 Algorithms & Computing Lecture #11 Instructor: Jahan Zeb Department of Computer Engineering (DCE) College of E&ME NUST.
Computer Codes Rohit Khokher. Computer Codes Data types NumericNonnumeric IntegerRealAlphabet A, B, C, …,Z a, b, c,…,z Digits 0,…,9 Special Characters.
C Characters & Strings Character Review Character Handling Library Initialization String Conversion Functions String Handling Library Standard Input/Output.
 2003 Prentice Hall, Inc. All rights reserved Fundamentals of Characters and Strings Character constant –Integer value represented as character.
Strings.
Lecture 9. Lecture 9: Outline Strings [Kochan, chap. 10] –Character Arrays/ Character Strings –Initializing Character Strings. The null string. –Escape.
 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.
Current Assignments Homework 5 will be available tomorrow and is due on Sunday. Arrays and Pointers Project 2 due tonight by midnight. Exam 2 on Monday.
Principles of Programming Fundamental of C Programming Language and Basic Input/Output Function 1.
 2000 Prentice Hall, Inc. All rights reserved. Chapter 8 - Characters and Strings Outline 8.1Introduction 8.2Fundamentals of Strings and Characters 8.3Character.
Chapter 8 Characters and Strings 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 Fundamentals of Strings and Characters Characters.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 8 - Characters and Strings Outline 8.1Introduction.
 2000 Prentice Hall, Inc. All rights reserved. Chapter 8 - Characters and Strings Outline 8.1Introduction 8.2Fundamentals of Strings and Characters 8.3Character.
Chapter 2: Introduction to C++.
Week 7 – String. Outline Passing Array to Function Print the Array How Arrays are passed in a function call Introduction to Strings String Type Character.
Chapter 3: Introduction to C Programming Language C development environment A simple program example Characters and tokens Structure of a C program –comment.
Variable & Constants. A variable is a name given to a storage area that our programs can manipulate. Each variable in C has a specific type, which determines.
 2007 Pearson Education, Inc. All rights reserved C Characters and Strings.
Bits, Bytes, KiloBytes, MegaBytes, GigaBytes & TeraBytes.
©Brooks/Cole, 2003 Chapter 2 Data Representation.
Homework Reading Programming Assignments
Chapter 2: C Fundamentals Dr. Ameer Ali. Overview C Character set Identifiers and Keywords Data Types Constants Variables and Arrays Declarations Expressions.
Computer System Basics 1 Number Systems & Text Representation Computer Forensics BACS 371.
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.
EPSII 59:006 Spring Introduction Fundamentals of Strings and Characters Character Handling Library String Conversion Functions Standard Input/Output.
C How to Program, 6/e © by Pearson Education, Inc. All Rights Reserved.
CHAPTER 8 CHARACTER AND STRINGS
1 Digital Technology and Computer Fundamentals Chapter 1 Data Representation and Numbering Systems.
 2000 Prentice Hall, Inc. All rights reserved. Chapter 8 - Characters and Strings Outline 8.1Introduction 8.2Fundamentals of Strings and Characters 8.3Character.
EX_01.1/46 Numeric Systems. EX_01.2/46 Overview Numeric systems – general, Binary numbers, Octal numbers, Hexadecimal system, Data units, ASCII code,
STRING Dong-Chul Kim BioMeCIS UTA 10/7/
Number Systems Spring Semester 2013Programming and Data Structure1.
CS1 Lesson 2 Introduction to C++ CS1 Lesson 2 -- John Cole1.
CH2 – Using Data. Constant Something which cannot be changed Data Type Format and size of a data item Intrinsic Data Types Pg. 47 – Table 2-1 Basic ones.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-1 Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.
Data & Data Types & Simple Math Operation 1 Data and Data Type Standard I/O Simple Math operation.
Copyright © 2012 Pearson Education, Inc. Chapter 2: Introduction to C++
Computer System Basics 1 Number Systems & Text Representation Computer Forensics BACS 371.
Copyright © 2015, 2012, 2009 Pearson Education, Inc., Publishing as Addison-Wesley All rights reserved. Chapter 2: Introduction to C++
Chapter 8 Characters and Strings Associate Prof. Yuh-Shyan Chen Dept. of Computer Science and Information Engineering National Chung-Cheng University.
Dale Roberts Department of Computer and Information Science, School of Science, IUPUI C-Style Strings Strings and String Functions Dale Roberts, Lecturer.
Chapter 8: Character and String CMPD144: Programming 1.
Codes Octal Power Hexadecimal ASCII BCD Code
CSC141- Introduction to Computer programming Teacher: AHMED MUMTAZ MUSTEHSAN Lecture – 21 Thanks for Lecture Slides:
Agenda Character representation Numerical Conversions ASCII EBCDIC
Chapter 7 C supports two fundamentally different kinds of numeric types: (a) integer types - whole numbers (1) signed (2) unsigned (b) floating types –
 2003 Prentice Hall, Inc. All rights reserved. 11 Fundamentals of Characters and Strings Character constant –Integer value of a character –Single quotes.
Chapter 8 Characters and Strings. Objectives In this chapter, you will learn: –To be able to use the functions of the character handling library ( ctype).
C++ Programming Lecture 19 Strings The Hashemite University Computer Engineering Department (Adapted from the textbook slides)
Principles of Programming Chapter 8: Character & String  In this chapter, you’ll learn about;  Fundamentals of Strings and Characters  The difference.
Chapter 4: Variables, Constants, and Arithmetic Operators Introduction to Programming with C++ Fourth Edition.
1 Chapter 8 - Characters and Strings Outline 8.1Introduction 8.2Fundamentals of Strings and Characters 8.3Character Handling Library 8.4String Conversion.
Dale Roberts Department of Computer and Information Science, School of Science, IUPUI CSCI 230 Characters and Strings Dale Roberts, Lecturer Computer Science,
Principles of Programming - NI Chapter 10: Character & String : In this chapter, you’ll learn about; Fundamentals of Strings and Characters The difference.
1 ENERGY 211 / CME 211 Lecture 3 September 26, 2008.
EC-111 Algorithms & Computing Lecture #10 Instructor: Jahan Zeb Department of Computer Engineering (DCE) College of E&ME NUST.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-1 Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.
2.1 The Part of a C++ Program. The Parts of a C++ Program // sample C++ program #include using namespace std; int main() { cout
Programming and Data Structure
Number Representation
C Characters and Strings
CS 108 Computing Fundamentals November 2, 2017.
Chapter 8 - Characters and Strings
2.1 Parts of a C++ Program.
Chapter 2: Introduction to C++.
C++ Programming Lecture 20 Strings
C Characters and Strings
Presentation transcript:

Characters and Strings Fundamentals of Strings and Characters Difference between an integer digit and a character digit Character handling library String conversion functions Standard input/output library functions String manipulation functions String comparison functions String search functions Memory functions

Fundamentals of Characters and Strings Characters in C consist of any printable or nonprintable character in the computer’s character set including lowercase letters, uppercase letters, decimal digits, special characters and escape sequences. A character is usually stored in the computer as an 8-bits (1 byte) integer. The integer value stored for a character depends on the character set used by the computer on which the program is running.

There are two commonly used character sets: ASCII (American Standard Code for Information Interchange) EBCDIC (Extended Binary Coded Decimal Interchange Code) A string in C is an array of characters ending with the null character (‘\0’). It is written inside a double quotation mark (“ ”). A string may be assign in a declaration to either a char array or to a char pointer: char color[] = “green”; OR char *color = “green”; A string can also be defined by specifying the individual characters: char color[] = {‘g’, ‘r’, ‘e’, ‘e’, ‘n’, ‘/0’};

In memory, these are the characters stored: A string is accessed via a pointer to the first character in the string. In memory, these are the characters stored: G R E E N /0 Notice that even though there are only five characters in the word ‘green’, six characters are stored in the computer. The last character, the character ‘/0’, is the NULL character which indicates the end of the string. Therefore, if an array of characters is to be used to store a string, the array must be large enough to store the string and its terminating NULL character.

Difference Between an Integer Digit and a Character Digit char num = 1 and char num = ‘1’ are not the same. char num = 1 is represented in the computer as 00000001. char num = ‘1’ on the other hand is number 49 according to the ASCII character set. Therefore, it is represented in the computer as 00110001. char *num = “1” is equivalent to char *num = {‘1’, ‘\0’}. It takes 2 bytes of space instead of 1 byte since it is declared as a string and therefore needs the terminating null character. In the computer, it is represented as 0011000100000000.

Character Handling Library Character handling library includes several function that perform useful tests and manipulation of character data. Each function receives a character, represented as an int or EOF, as an argument. When using functions from the character handling library, the header file <ctype.h> needs to be included. Characters in these functions are manipulated as integers (since a character is basically a 1 byte integer).

String Conversion Functions These functions convert strings of digits to integer and floating-point values. To use these functions, the general utilities library <stdlib.h>, needs to be included. Note that these functions take a constant value as their argument. This means that we can only pass a constant string to the functions. For example: atoi (“1234”); const char *hello = “9999”; atoi(hello);

nPtr - The pointer to the string to be converted. endptr - The pointer to which the remainder of the string will be assigned after the conversion. We can pass a NULL if the remaining string is to be ignored. base - Indicates the format (base) of the string to be converted. If 0 is given, that means the value to be converted can be in octal (base 8), decimal (base 10) or hexadecimal (base 16).

Standard Input/Output Library Functions Include <stdio.h> to use these functions.

String Manipulation Functions Include <string.h> to use these functions.

String Comparison Functions Include <string.h> to use these functions

String Search Functions Include <string.h> to use these functions.

String Memory Functions Include <string.h> to use these functions.