Getting Started

(lily) #1

Chapter 5: C Control Flow


We define non-printable characters using escape sequences and I guess this is just
about a


k at the next function, take out you paper and pencil computer and

ought and see what you come up with. I’m serious now,
t or
9: ASCII Table (in appendixes) and note
e nd 4 are sequential integer numerals, 0x31, 0x32,
, and 0x34.

//NOTE: stolen from K&R p. 43 atoi function
)

i] <= '9'; ++i)

s good a place as any to show them all:

Table 8: Escape Sequences
\a alert (bell)
\b backspace
\f formfeed
\n newline
\r carriage return
\t horizontal tab
\v vertical tab
\\ backslash
\? question mark
\’ single quote
\” double quote
\000 octal number
\xhh hexadecimal number
\0 null

Before you loo
come up with an algorithm for converting an ASCII character string of numerals
into an integer, for example convert the string of char data types: “1234” to the int



  1. Give this some th
    do i the rest of the ink in the book will fade away and you’ll have an expensive
    drawing pad. Need a hint? Look at Table
    that th characters for 1, 2, 3, a
    0 x33


int atoi(char s[]
{
int i, n;

n = 0;
for(i = 0; s[i] >= '0' && s[
n = 10 * n + (s[i] - '0');
return n;
Free download pdf