| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1444 人关注过本帖
标题:各位好心帮我看看错在哪里???
取消只看楼主 加入收藏
TARGET_MG42
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2004-8-7
收藏
 问题点数:0 回复次数:3 
各位好心帮我看看错在哪里???
各位好心帮我看看错在哪里??? #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
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
TARGET_MG42
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2004-8-7
收藏
得分:0 
非常感谢各位指教!!!多谢,多谢,多多谢!!!
2004-08-09 22:01
快速回复:各位好心帮我看看错在哪里???
数据加载中...
 
   



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

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