Fixing the Bug


You have determined that the bug sits on line 7 of tblank.c:


slength = strlen(s);


Because of C's array indexing rules (arrays begin with 0, not with 1), 
strlen() returns a value that needs to be decremented before 
being assigned to slength. Edit tblank.c so that 
line 7 looks like this:


slength = strlen(s)-1;


Now make debug, and try dbx again:


coke-23: make debug

cc -g main.c preblank.c adjstring.c tblank.c

main.c:

preblank.c:

adjstring.c:

tblank.c:

coke-24: dbx a.out

dbx version 3.12 of 12/6/85 8:35 (paris).

Type 'help' for help.

reading symbolic information ...


Try retracing the variables in tblank.c:


(dbx) trace s in tblank

[using tblank.tblank.s]

[1] trace tblank.tblank.s in tblank

(dbx) trace slength in tblank

[2] trace slength in tblank

(dbx) run

Enter a string with leading and trailing blanks:

    asdf

input = '    asdf    '

initially (at line 7 in "tblank.c"):   tblank.tblank.s

 = "asdf    "

initially (at line 7 in "tblank.c"):   slength = 4

after line 9 in "tblank.c":    slength = 7

after line 12 in "tblank.c":   slength = 6

after line 12 in "tblank.c":   slength = 5

after line 12 in "tblank.c":   slength = 4

after line 12 in "tblank.c":   slength = 3

after line 14 in "tblank.c":   slength = 4

output = 'asdf'


execution completed

(dbx) quit


Now that you have repaired the bug, build a new blankstrip:


coke-26: make

cc -c tblank.c

cc main.o preblank.o adjstring.o tblank.o -o blankstrip