| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1444 人关注过本帖
标题:各位好心帮我看看错在哪里???
只看楼主 加入收藏
TARGET_MG42
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2004-8-7
收藏
 问题点数:0 回复次数:10 
各位好心帮我看看错在哪里???
各位好心帮我看看错在哪里??? #include<stdio.h> struct wordlist {char word[20]; char explain[40]; };

struct wordlist words[25]={{"abandon","vt,遗弃;放弃"}, {"abbreviation","n,缩写"}, {"abide","vt,忍受,容忍"}, {"ability","n,能力;才能"}, {"abnormal","n,异常的,反常的"}, {"aboard","在船,车,飞机上,上船(或车、飞机)"}, {"abolish","vt,废除"}, {"abortion","n,流产,堕胎;失败"} };

char input[20]; int words_index=0;

void main() {check_word: printf("%s\n",words[words_index].explain); scanf("%s\n",input); int _index=0;/*C:\TG42_C\word_exercise1.0.c(24) : error C2143: syntax error : missing ';' before 'type'*/

for(;words[words_index].word[_index]!='\0';_index++) {if(input[_index]!=words[words_index].word[_index]) {printf("单词输入错误!请重新输入:\n"); goto check_word;} } if (input[_index]!='\0') {printf("单词输入错误!请重新输入:\n"); goto check_word;} words_index++; if(words[words_index].word[0]!='\0') goto check_word; else printf("单词练习完毕!\n"); } 错误提示见注解!

搜索更多相关主题的帖子: quot 好心 堕胎 流产 char 
2004-08-09 09:02
TARGET_MG42
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2004-8-7
收藏
得分:0 
另一个正确的C++版本:
#include&lt;iostream.h&gt;
struct wordlist
{char word[20];
char explain[40];
};
///////////单词定义
struct wordlist words[25]={{"abandon","vt,遗弃;放弃"},
{"abbreviation","n,缩写"},
{"abide","vt,忍受,容忍"},
{"ability","n,能力;才能"},
{"abnormal","n,异常的,反常的"},
{"aboard","在船,车,飞机上,上船(或车、飞机)"},
{"abolish","vt,废除"},
{"abortion","n,流产,堕胎;失败"}
};
///////
char input[20];
int words_index=0;
///////main
void main()
{check_word:
 cout&lt;&lt;words[words_index].explain&lt;&lt;endl;
 cin&gt;&gt;input;
 int _index=0;
 for(;words[words_index].word[_index]!='\0';_index++)
 {if(input[_index]!=words[words_index].word[_index])
 {cout&lt;&lt;"单词输入错误!请重新输入:\n";
 goto check_word;}
 }
 if (input[_index]!='\0')
 {cout&lt;&lt;"单词输入错误!请重新输入:\n";
 goto check_word;}
 words_index++;
 if(words[words_index].word[0]!='\0')
 goto check_word;
 else cout&lt;&lt;"单词练习完毕!\n";
}
这两个程序仅仅只是输入输出函数不同,头文件不同,其他都一样,我搞不懂为何C++没问题,而C就出问题!
2004-08-09 09:02
神vLinux飘飘
Rank: 13Rank: 13Rank: 13Rank: 13
来 自:浙江杭州
等 级:贵宾
威 望:91
帖 子:6140
专家分:217
注 册:2004-7-17
收藏
得分:0 

#include<stdio.h> struct wordlist {char word[20]; char explain[40]; };

struct wordlist words[25]={{"abandon","vt,遗弃;放弃"}, {"abbreviation","n,缩写"}, {"abide","vt,忍受,容忍"}, {"ability","n,能力;才能"}, {"abnormal","n,异常的,反常的"}, {"aboard","在船,车,飞机上,上船(或车、飞机)"}, {"abolish","vt,废除"}, {"abortion","n,流产,堕胎;失败"} };

char input[20]; int words_index=0;

void main() {check_word: printf("%s\n",words[words_index].explain); scanf("%s\n",input); /*int words_index=0;*/

for(;words[words_index].word[words_index]!='\0';words_index++) {if(input[words_index]!=words[words_index].word[words_index]) {printf("单词输入错误!请重新输入:\n"); goto check_word;} } if (input[words_index]!='\0') {printf("单词输入错误!请重新输入:\n"); goto check_word;} words_index++; if(words[words_index].word[0]!='\0') goto check_word; else printf("单词练习完毕!\n"); }

没什么大错误,只是有些 words_index 前面少打了 words 变成了_index 还有,你重复定义了words_index 要删除掉main()中的那个

最后,这个程序必须要在中文环境下才能正常显示汉字,也就是说:用UCDOS来执行吧


淘宝杜琨
2004-08-09 09:10
yms123
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:209
帖 子:12488
专家分:19042
注 册:2004-7-17
收藏
得分:0 
以下是引用TARGET_MG42在2004-08-09 09:02:00的发言: 各位好心帮我看看错在哪里??? #include<stdio.h> struct wordlist {char word[20]; char explain[40]; };

struct wordlist words[25]={{"abandon","vt,遗弃;放弃"}, {"abbreviation","n,缩写"}, {"abide","vt,忍受,容忍"}, {"ability","n,能力;才能"}, {"abnormal","n,异常的,反常的"}, {"aboard","在船,车,飞机上,上船(或车、飞机)"}, {"abolish","vt,废除"}, {"abortion","n,流产,堕胎;失败"} };

char input[20]; int words_index=0;

void main() {check_word: printf("%s\n",words[words_index].explain); scanf("%s\n",input); int _index=0;/*C:\TG42_C\word_exercise1.0.c(24) : error C2143: syntax error : missing ';' before 'type'*/

for(;words[words_index].word[_index]!='\0';_index++) {if(input[_index]!=words[words_index].word[_index]) {printf("单词输入错误!请重新输入:\n"); goto check_word;} } if (input[_index]!='\0') {printf("单词输入错误!请重新输入:\n"); goto check_word;} words_index++; if(words[words_index].word[0]!='\0') goto check_word; else printf("单词练习完毕!\n"); } 错误提示见注解!

;/*C:\TG42_C\word_exercise1.0.c(24) : error C2143: syntax error : missing ';' before 'type'*/这是编译器生成的吧?你怎么给写进里面去了?不过还是那个C++的看着比较规范。

2004-08-09 09:16
TARGET_MG42
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2004-8-7
收藏
得分:0 

我前面定义了一个全局变量words_index,用来表示单词顺序

后面定义的局部变量_index,用来比较输入单词与原单词

并非我少输了words,但我不清楚的是

我仅仅只是把C++中的头文件iostream.h换成了c中的stdio.h

另外用printf和scanf替换了cout和cin

那为什么会出现C:\TG42_C\word_exercise1.0.c(24) : error C2143: syntax error : missing ';' before 'type'*/的错误???

还有一般书上都反感使用GOTO语句,可我觉得GOTO使用很方便

不知各位有什么看法?

2004-08-09 09:51
神vLinux飘飘
Rank: 13Rank: 13Rank: 13Rank: 13
来 自:浙江杭州
等 级:贵宾
威 望:91
帖 子:6140
专家分:217
注 册:2004-7-17
收藏
得分:0 

其他问题我还得慢慢看,

先批判一下GOTO,GOTO 臭名招著 因为他是无条件跳转,用不好会影响到变量的值,


淘宝杜琨
2004-08-09 12:42
live41
Rank: 10Rank: 10Rank: 10
等 级:贵宾
威 望:67
帖 子:12442
专家分:0
注 册:2004-7-22
收藏
得分:0 

“各位好心,行行方便”。我说主题怎么有点想乞丐的那个……(刀子扛在脖上不敢说下去)

goto太乱了,短程序还可以,如果太长就会看死别人,人家看你个goto都不知道你tmd转去哪了,可能有点偏激,我说过pascal被淘汰就是指它的goto,这个始终是过去了……

2004-08-09 13:01
youthlin
Rank: 1
等 级:新手上路
帖 子:36
专家分:0
注 册:2004-8-7
收藏
得分:0 

有道理啊,程序长了的话,GOTO太难找了,程序的 可读性,条理性降低了很多,晕,我怎么打到中文显示了乱码

2004-08-09 15:19
神vLinux飘飘
Rank: 13Rank: 13Rank: 13Rank: 13
来 自:浙江杭州
等 级:贵宾
威 望:91
帖 子:6140
专家分:217
注 册:2004-7-17
收藏
得分:0 

#include<stdio.h>

struct wordlist{ char English[20]; char Chinese[100]; };

struct wordlist words[8]={ {"DeadKnight","n,死亡骑士"}, {"DemonHunter","n,恶魔猎手"}, {"archer","n,弓箭手"}, {"StarFall","n,星辰坠落"}, {"DeadCoil","n,死亡缠绕"}, {"Priest","n,牧师"}, {"NeightElf","n,月夜精灵"}, {"Templar","n,圣堂武士"} };

void main() { int n; char inputs[20];

for(n=0;n<8;){ printf("中文:%s\n",words[n].Chinese); scanf("%s",inputs);

if(strcmp(words[n].English,inputs)==0){ printf("算你狗对了,继续!\n\n"); n++; }

else{ printf("你这个白痴,正确答案是: %s\n",words[n].English); printf("真是个废物,再来一次!\n\n");

} }

printf("全部狗对了,做的不错兄弟!"); getch();

}

/*该程序必须要UCDOS的支持!*/


淘宝杜琨
2004-08-09 19:11
mingyue
Rank: 1
等 级:新手上路
帖 子:60
专家分:0
注 册:2004-5-13
收藏
得分:0 
以下是引用TARGET_MG42在2004-08-09 09:51:00的发言:

我前面定义了一个全局变量words_index,用来表示单词顺序

后面定义的局部变量_index,用来比较输入单词与原单词

并非我少输了words,但我不清楚的是

我仅仅只是把C++中的头文件iostream.h换成了c中的stdio.h

另外用printf和scanf替换了cout和cin

那为什么会出现C:\TG42_C\word_exercise1.0.c(24) : error C2143: syntax error : missing ';' before 'type'*/的错误???

C语言要把变量声明放在函数的开头部分,不支持在函数中间声明变量。


2004-08-09 20:39
快速回复:各位好心帮我看看错在哪里???
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.016952 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved