20.09.2015 Views

Programming in C

Kochan - ProgramminginC

Kochan - ProgramminginC

SHOW MORE
SHOW LESS

Create successful ePaper yourself

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

Character Str<strong>in</strong>gs, Structures, and Arrays<br />

221<br />

Program 10.9 Cont<strong>in</strong>ued<br />

char def<strong>in</strong>ition[50];<br />

};<br />

/***** Insert equalStr<strong>in</strong>gs function here *****/<br />

// function to look up a word <strong>in</strong>side a dictionary<br />

<strong>in</strong>t lookup (const struct entry dictionary[], const char search[],<br />

const <strong>in</strong>t entries)<br />

{<br />

<strong>in</strong>t i;<br />

bool equalStr<strong>in</strong>gs (const char s1[], const char s2[]);<br />

for ( i = 0; i < entries; ++i )<br />

if ( equalStr<strong>in</strong>gs (search, dictionary[i].word) )<br />

return i;<br />

}<br />

return -1;<br />

<strong>in</strong>t ma<strong>in</strong> (void)<br />

{<br />

const struct entry dictionary[100] =<br />

{ { "aardvark", "a burrow<strong>in</strong>g African mammal" },<br />

{ "abyss", "a bottomless pit" },<br />

{ "acumen", "mentally sharp; keen" },<br />

{ "addle", "to become confused" },<br />

{ "aerie", "a high nest" },<br />

{ "affix", "to append; attach" },<br />

{ "agar", "a jelly made from seaweed" },<br />

{ "ahoy", "a nautical call of greet<strong>in</strong>g" },<br />

{ "aigrette", "an ornamental cluster of feathers" },<br />

{ "ajar", "partially opened" } };<br />

char word[10];<br />

<strong>in</strong>t entries = 10;<br />

<strong>in</strong>t entry;<br />

<strong>in</strong>t lookup (const struct entry dictionary[], const char search[],<br />

const <strong>in</strong>t entries);<br />

pr<strong>in</strong>tf ("Enter word: ");<br />

scanf ("%14s", word);<br />

entry = lookup (dictionary, word, entries);<br />

if ( entry != -1 )<br />

pr<strong>in</strong>tf ("%s\n", dictionary[entry].def<strong>in</strong>ition);

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

Saved successfully!

Ooh no, something went wrong!