在线急求此C++问题!~~~

来源:百度知道 编辑:UC知道 时间:2024/06/18 03:42:55
很急,请帮忙耐心看一下,主函数是不是有问题,输出翻译时是1...求解~~
#include <iostream>
#include <string.h>
using namespace std;
class Dic
{
public:
void add(char w[],char m[]);
void trans(char str[]);
private:
char words[100][30];
char mean[100][30];
int top;
};
void Dic::add(char w[],char m[])
{
strcpy(words[top],w);
strcpy(mean[top],m);
top++;
}
void Dic::trans(char str[])
{
int i=0,j=0,s;
char w[30];
while(1){
if(str[i]!=' '&&str[i]!='\0')
w[j++]=str[i];
else{
w[j]='\0';
for(s=0;s<top;s++)
if(strcmp(words[s],w)==0)
break;
if(s<top){
strcpy(w,mean[s]);
cout<<w;
}
else{
strcpy(w,"unknown");
cout<<w;
}
j=0;
if(str[i]=='\0')
break;

除了最后一句的问题, void trans(char str[]);的函数有问题,运行通过不了。

#include <iostream>
#include <string.h>
using namespace std;
class Dic
{
public:
void add(char w[],char m[]);
void trans(char str[]);
int top;
private:
char words[100][30];
char mean[100][30];

};
void Dic::add(char w[],char m[])
{
strcpy(words[top],w);
strcpy(mean[top],m);
top++;
}
void Dic::trans(char str[])
{
int i=0,j=0,s;
char w[30];
while(1){
if(str[i]!=' '&&str[i]!='\0')
w[j++]=str[i];
else{
w[j]='\0';
for(s=0;s<top;s++)
if(strcmp(words[s],w)==0)
break;
if(s<top){
strcpy(w,mean[s]);
cout<<w;
}
else{
strcpy(w,"unknown");
cout<<w;
}
j=0;
if(str[i]=='\