J
jim
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;
}
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;
}