Ch10 - CSEB114:PrincipleofProgramming...

Info iconThis preview shows pages 1–10. Sign up to view the full content.

View Full Document Right Arrow Icon
Click to edit Master subtitle style 9/25/2008 prepared by NI, edited by MAF CSEB114: Principle of Programming Chapter 9: Character and String
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
9/25/2008 prepared by NI, edited by MAF Objectives In this chapter, you’ll learn about; Fundamentals of Strings and Characters The difference between an integer digit and a character digit Character handling library String conversion functions Standard input/output library functions String manipulation functions
Background image of page 2
9/25/2008 prepared by NI, edited by MAF 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.
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
9/25/2008 prepared by NI, edited by MAF Fundamentals of Characters and Strings There are two commonly used character sets: ASCII (American Standard Code for Information Interchange) EBCDIC (Extended Binary Coded Decimal Interchange Code)
Background image of page 4
9/25/2008 prepared by NI, edited by MAF 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.
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
9/25/2008 prepared by NI, edited by MAF Example: ASCII character #include <stdio.h> void main(void) { char my_A = 'A'; char my_Z = 'Z'; char my_a = 'a'; char my_z = 'z'; printf("\nASCII value for A is %d", my_A); printf("\nASCII value for Z is %d",my_Z); printf("\nASCII value for a is %d", my_a); printf("\nASCII value for z is %d",my_z); printf("\n"); printf("\n65 in ASCII represents %c",65); printf("\n90 in ASCII represents %c",90);
Background image of page 6
9/25/2008 prepared by NI, edited by MAF Sample output ASCII value for A is 65 ASCII value for Z is 90 ASCII value for a is 97 ASCII value for z is 122 65 in ASCII represents A 90 in ASCII represents Z 97 in ASCII represents a 122 in ASCII represents z
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
9/25/2008 prepared by NI, edited by MAF Example cont… #include <stdio.h> void main(void) { char ch; printf("enter a character: "); scanf("%c", &ch); { printf("\ncapital letter\n"); } } #include <stdio.h> void main(void) { char ch; printf("enter a character: "); scanf("%c", &ch); if (ch >= 65 && ch <= (65+26)) equivalen
Background image of page 8
9/25/2008 prepared by NI, edited by MAF Fundamentals of Characters and Strings 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 assigned (in a declaration) to either a char array or to a char pointer: char color[] = “green”; OR char *color = “green”;
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 10
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 06/01/2011 for the course ECON 101 taught by Professor Yip during the Spring '11 term at Al-Quds University.

Page1 / 37

Ch10 - CSEB114:PrincipleofProgramming...

This preview shows document pages 1 - 10. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online