08.01.2023 Views

Learn to Program with C_ Learn to Program using the Popular C Programming Language ( PDFDrive )

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 6

Characters

In this chapter, we will explain the following:

• Some important features of character sets

• How to work with character constants and values

• How to declare character variables in C

• How you can use characters in arithmetic expressions

• How to read, manipulate, and print characters

• How to test for end-of-line using \n

• How to test for end-of-file using EOF

• How to compare characters

• How to read characters from a file

• How to convert a number from character to integer

6.1 Character Sets

Most of us are familiar with a computer or typewriter keyboard (called the standard English

keyboard). On it, we can type the letters of the alphabet (both uppercase and lowercase), the

digits and other ‘special’ characters like +, =, <, >, &, and %—these are the so-called printable

characters.

On a computer, each character is assigned a unique integer value, called its code. This code

may be different from one computer to another depending on the character set being used. For

example, the code for A might be 33 on one computer but 65 on another.

Inside the computer, this integer code is stored as a sequence of bits; for example, the 6-bit

code for 33 is 100001 and the 7-bit code for 65 is 1000001.

Nowadays, most computers use the ASCII (American Standard Code for Information

Interchange) character set for representing characters. This is a 7-bit character standard that

includes the letters, digits, and special characters found on a standard keyboard. It also includes

control characters such as backspace, tab, line feed, form feed, and carriage return.

141

www.it-ebooks.info

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!