读书人

声明调用函数时出现异常

发布时间: 2012-02-06 15:52:44 作者: rapoo

声明调用函数时出现错误!
#include <stdio.h>
main(){

char str[100];
gets(str);
maxlong(str);

puts(str);

}
maxlong(char *str){
int ml,i,count,wz;
count=0;
wz=0;
ml=0;
for (i=0;str[i]!= '\0 ';i++)
if (str[i]!= ' ')
{
count++;
if(str[i+1]== '\0 '&&ml <count){
ml=count;wz=i-count+1;}
}
else{
if (ml <count){
ml=count;wz=i-count;}
count=0;
}

for (i=0;str[i+wz]!= ' '&&str[i+wz]!= '\0 ';i++)
str[i]=str[i+wz];
str[i]= '\0 ';
}
/*看看上面函数,为什么在程序第三行中声明void maxlong(char)就会出错,
出错提示:第6行 tpye mismatch in parameter 1 in call to 'maxlong ' in function main
第11行 type mismatch in redeclaration

[解决办法]
maxlong(char *str){...}
==》
void maxlong(char *str){...}

void maxlong(char)
==》
void maxlong(char *)

读书人网 >C语言

热点推荐