c++菜鸟求解

qiangwushuang 2011-11-27 10:12:38
#include <iostream>
using namespace std;
int main()
{int max_string(char string1 [],char string2 []);
int i=0,j=0;
char s1[40],s2[40];
cout<<input<<s1<<endl;
cin>>s1;
cout<<input<<s2<<endl;
cin>>s2;
cout<<max_string(s1[40],s2[40])<<endl;
return 0;}
int max_string(char string1[],char string2[])
{int i,j;
for(i=0;i<40;i++)
for(j=i,j<=i,j++)
{if(s[i]=s[j])continue;
else if(s[i]>s[j]);return s[i];
else return s[j];}}

1>------ 已启动生成: 项目: 12, 配置: Debug Win32 ------
1>生成启动时间为 2011-11-27 21:59:32。
1>InitializeBuildStatus:
1> 正在对“Debug\12.unsuccessfulbuild”执行 Touch 任务。
1>ClCompile:
1> 34.cpp
1>c:\users\lenovo\desktop\12\12\34.cpp(8): error C2664: “max_string”: 不能将参数 1 从“char”转换为“char []”
1> 从整型转换为指针类型要求 reinterpret_cast、C 样式转换或函数样式转换
1>c:\users\lenovo\desktop\12\12\34.cpp(13): error C2143: 语法错误 : 缺少“;”(在“)”的前面)
1>c:\users\lenovo\desktop\12\12\34.cpp(13): error C2143: 语法错误 : 缺少“;”(在“)”的前面)
1>c:\users\lenovo\desktop\12\12\34.cpp(14): error C2065: “s”: 未声明的标识符
1>c:\users\lenovo\desktop\12\12\34.cpp(14): error C2065: “s”: 未声明的标识符
1>c:\users\lenovo\desktop\12\12\34.cpp(15): error C2065: “s”: 未声明的标识符
1>c:\users\lenovo\desktop\12\12\34.cpp(15): error C2065: “s”: 未声明的标识符
1>c:\users\lenovo\desktop\12\12\34.cpp(15): warning C4390: “;”: 找到空的受控语句;这是否是有意的?
1>c:\users\lenovo\desktop\12\12\34.cpp(15): error C2065: “s”: 未声明的标识符
1>c:\users\lenovo\desktop\12\12\34.cpp(16): error C2181: 没有匹配 if 的非法 else
1>c:\users\lenovo\desktop\12\12\34.cpp(16): error C2065: “s”: 未声明的标识符
1>
1>生成失败。
1>
1>已用时间 00:00:00.45
========== 生成: 成功 0 个,失败 1 个,最新 0 个,跳过 0 个 ==========

error C2664: “max_string”: 不能将参数 1 从“char”转换为“char 什么意思,如何修改???
...全文
139 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
qscool1987 2011-11-28
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 hnuqinhuan 的回复:]
C/C++ code

#include <iostream>
using namespace std;
int main()
{
int max_string(char string1 [],char string2 []);
int i=0,j=0;
char s1[40],s2[40];
cout<<"input s1"<<endl;
……
[/Quote]
参考这个,你那很多问题
xingfeng2510 2011-11-27
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 xingfeng2510 的回复:]

错误地方太多,直接看下面的代码吧
C/C++ code

#include <iostream>
using namespace std;
int main()
{
int max_string(char *string1,char *string2);
int i=0,j=0;
char s1[40],s2[40];
cout<<s1<<endl;
c……
[/Quote]
存在逻辑错误,仅保证可以编译,可以做个参考。
xingfeng2510 2011-11-27
  • 打赏
  • 举报
回复
错误地方太多,直接看下面的代码吧

#include <iostream>
using namespace std;
int main()
{
int max_string(char *string1,char *string2);
int i=0,j=0;
char s1[40],s2[40];
cout<<s1<<endl;
cin>>s1;
cout<<s2<<endl;
cin>>s2;
cout<<max_string(s1,s2)<<endl;
return 0;
}

int max_string(char *string1,char *string2)
{
int i,j;
for(i=0;i<40;i++)
{
for(j=i;j<=i;j++)
{
if(string1[i]=string2[j])
continue;
else if(string1[i]>string2[j])
return string1[i];
else
return string2[j];
}
}
return 0;
}
柯本 2011-11-27
  • 打赏
  • 举报
回复
按你的改下,参考下吧

#include <iostream>
using namespace std;
int main()
{int max_string(char string1 [],char string2 []);
int i=0,j=0;
char s1[40],s2[40];
cout<<" input s1:" <<endl; //input没定义,不知你要在没数据情况下输出什么
cin>>s1;
cout<<" input s2:" <<endl;
cin>>s2;
cout<<max_string(s1,s2)<<endl; //传的是地址,不是值
return 0;}
int max_string(char s1[],char s2[])
{int i,j;
for(i=0;i<40;i++)
for(j=i;j<=i;j++) //分号不是,号
{
if(s1[i]=s2[j])continue; //s1,s2没有,改前面的
else
if(s1[i]>s2[j]) //多;号
return s1[i];
else return s2[j];

}
}

tuccty 2011-11-27
  • 打赏
  • 举报
回复
参考3楼
LAST_MAN 2011-11-27
  • 打赏
  • 举报
回复
cout<<input<<s1<<endl;
input要加引号
s未声明
先改这2个试下
無_1024 2011-11-27
  • 打赏
  • 举报
回复

#include <iostream>
using namespace std;
int main()
{
int max_string(char string1 [],char string2 []);
int i=0,j=0;
char s1[40],s2[40];
cout<<"input s1"<<endl;
cin>>s1;
cout<<"input s2"<<endl;
cin>>s2;
cout<<max_string(s1,s2)<<endl;
return 0;
}
//相等返回0 string1 大于string2返回1 反之返回-1
int max_string(char string1[],char string2[])
{
int i,j;
for(i=0;i<40;i++)
{
for(j=i;j<=i;j++)
{
if(string1[i]==string2[j])//-----
continue;
else if(string1[i] > string2[j])//多余分号
return 1;
else
return -1;
}
}
return 0;
}
//好好看看吧
yujie_v 2011-11-27
  • 打赏
  • 举报
回复
类型不匹配的
無_1024 2011-11-27
  • 打赏
  • 举报
回复
数组不能转换为字符啊

64,642

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧