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 时出错.
谢谢。