| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 11964 人关注过本帖
标题:cannot convert parameter 1 from 'char *[20]' to 'char *'
取消只看楼主 加入收藏
roslin1986
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2010-7-14
结帖率:50%
收藏
已结贴  问题点数:10 回复次数:3 
cannot convert parameter 1 from 'char *[20]' to 'char *'
下面这段程序大家看看有什么问题啊,小弟搞不定了。。
#include "stdio.h"
#include "string.h"
char swap(char *p1[20],char *p2[20])
{
    char *p[20];
    strcpy(p,p1);
    strcpy(p1,p2);
    strcpy(p2,p);
}
void main()
{
    char *str1[20],*str2[20],*str3[20];
    char swap();
    printf("Input three lines:\n");
    gets(str1);
    gets(str2);
    gets(str3);
    if(strcmp(str1,str2)>0) swap(str1,str2);
    if(strcmp(str1,str3)>0) swap(str1,str3);
    if(strcmp(str2,str3)>0) swap(str2,str3);
    printf("Now the order is:\n");
    printf("%s\n%s\n%s\n",str1,str2,str3);
}
下面是详细的错误信息:
e:\program files\microsoft visual studio\myprojects\1040\1040.cpp(6) : error C2664: 'strcpy' : cannot convert parameter 1 from 'char *[20]' to 'char *'
        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
e:\program files\microsoft visual studio\myprojects\1040\1040.cpp(7) : error C2664: 'strcpy' : cannot convert parameter 1 from 'char *[]' to 'char *'
        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
e:\program files\microsoft visual studio\myprojects\1040\1040.cpp(8) : error C2664: 'strcpy' : cannot convert parameter 1 from 'char *[]' to 'char *'
        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
e:\program files\microsoft visual studio\myprojects\1040\1040.cpp(15) : error C2664: 'gets' : cannot convert parameter 1 from 'char *[20]' to 'char *'
        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
e:\program files\microsoft visual studio\myprojects\1040\1040.cpp(16) : error C2664: 'gets' : cannot convert parameter 1 from 'char *[20]' to 'char *'
        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
e:\program files\microsoft visual studio\myprojects\1040\1040.cpp(17) : error C2664: 'gets' : cannot convert parameter 1 from 'char *[20]' to 'char *'
        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
e:\program files\microsoft visual studio\myprojects\1040\1040.cpp(18) : error C2664: 'strcmp' : cannot convert parameter 1 from 'char *[20]' to 'const char *'
        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
e:\program files\microsoft visual studio\myprojects\1040\1040.cpp(18) : error C2660: 'swap' : function does not take 2 parameters
e:\program files\microsoft visual studio\myprojects\1040\1040.cpp(19) : error C2664: 'strcmp' : cannot convert parameter 1 from 'char *[20]' to 'const char *'
        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
e:\program files\microsoft visual studio\myprojects\1040\1040.cpp(19) : error C2660: 'swap' : function does not take 2 parameters
e:\program files\microsoft visual studio\myprojects\1040\1040.cpp(20) : error C2664: 'strcmp' : cannot convert parameter 1 from 'char *[20]' to 'const char *'
        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
e:\program files\microsoft visual studio\myprojects\1040\1040.cpp(20) : error C2660: 'swap' : function does not take 2 parameters
执行 cl.exe 时出错.
谢谢。
搜索更多相关主题的帖子: parameter convert cannot char 
2010-07-14 20:00
roslin1986
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2010-7-14
收藏
得分:0 
回复 2楼 gyx8899
多谢啊。但是我最近在练习指针的用法,用指针这个程序该怎么改呢
2010-07-15 18:26
roslin1986
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2010-7-14
收藏
得分:0 
回复 4楼 gyx8899
。char p1[],p2[];这是定义的字符数组,不是指针啊。char *p1[],*p2[];才是定义的指针数组啊。高手指点
2010-07-19 15:12
roslin1986
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2010-7-14
收藏
得分:0 
回复 7楼 erikyo
非常感谢啊,这么编问题就解决了。也谢谢楼上其他各位啊
2010-07-21 19:51
快速回复:cannot convert parameter 1 from 'char *[20]' to 'char *'
数据加载中...
 
   



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

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