Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > c question

Reply
Thread Tools

c question

 
 
jim
Guest
Posts: n/a
 
      08-26-2004
I am reading c:the complete reference, fourth edition by herbert
schildt.
I think the following program has a bug
#include <stdio.h>
#include <string.h>
#include <ctype.h>

char *dic[][40]={
"atlas","A volume of maps",
"car","A motorized vehicle",
"telephone","a communication device",
"airport","A flying matchine",
"",""
};

int main(void)
{
char word[80],ch;
char **p;

do{
puts("\nenter words:");
scanf("%s",word);
p=(char **)dic;
do {
if(!strcmp(*p,word)){
puts("meaning:");
puts(*(p+1));
break;
}
if(!strcmp(*p,word)) break;
p=p+2;
}while(*p);
if(!*p) puts("word not in dictionary");
printf("Another ?:");
scanf(" %c" , &ch);
} while(toupper(ch) !='N');
return 0;
}



Although the above version runs, I think the definition of dic is not
correct. the correct version should be
#include <stdio.h>
#include <string.h>
#include <ctype.h>

char dic[][40]={
"atlas","A volume of maps",
"car","A motorized vehicle",
"telephone","a communication device",
"airport","A flying matchine",
"",""
};

int main(void)
{
char word[80],ch;
char (*p)[40];

do{
puts("\nenter words:");
scanf("%s",word);
p=(char (*)[40])dic;
do {
if(!strcmp(*p,word)){
puts("meaning:");
puts(*(p+1));
break;
}
if(!strcmp(*p,word)) break;
p=p+2;
}while(**p);
if(!**p) puts("word not in dictionary");
printf("Another ?:");
scanf(" %c" , &ch);
} while(toupper(ch) !='N');
return 0;
}
 
Reply With Quote
 
 
 
 
CBFalconer
Guest
Posts: n/a
 
      08-26-2004
jim wrote:
>
> I am reading c:the complete reference, fourth edition by herbert
> schildt.
> I think the following program has a bug
> #include <stdio.h>
> #include <string.h>
> #include <ctype.h>


Of course. It is by Schildt. Never expect correct code from him.

--
Chuck F ((E-Mail Removed)) ((E-Mail Removed))
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net> USE worldnet address!


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
question row filter (more of sql query question) =?Utf-8?B?YW5kcmV3MDA3?= ASP .Net 2 10-06-2005 01:07 PM
Quick Question - Newby Question =?Utf-8?B?UnlhbiBTbWl0aA==?= ASP .Net 4 02-16-2005 11:59 AM
Question on Transcender Question :-) eddiec MCSE 6 05-20-2004 06:59 AM
Question re: features of the 831 router (also a 924 question) Wayne Cisco 0 03-02-2004 07:57 PM
Syntax Question - Novice Question sean ASP .Net 1 10-20-2003 12:18 PM



Advertisments