编译出错,大家帮忙看看

henryluo henryluo 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
下面的函数目地是搜索第N个子串出现的位置,并截掉后面或前面部份(用N是正负表示)在做成一个程序时测试成功,但在做成函数形式时,编译出错,大家帮我看看,谢谢了



[root@localhost livecore.cc]# cat trimrstr.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

main()
{
char link[500];
char *string="<TR><td width=25><img src=img/space.gif border=0 width=1height=2></td><TD class=menuCountry><A class=menuLink href=index.php?s=21&lang=en&id=&g=s&g_m=s&g_i=&l=&c=16&live=true&result=><B>USA</B></A></TD><td width=15><img src=img/space.gif border=0 width=1 height=2></td></TR>";
int repeat=3;
char *sub="img";
strcpy(link,trimstr(string,repeat,sub));
printf("%s",link);
}


char *
trimstr(char *string,int repeat,char *sub)
{

char *current;
char *last;
char dest[strlen(string)];
int i;

printf("%s\n\n",string);
current=string;
for (i=1;i <= abs(repeat);i++)
{
last = current;
current=strstr(last+1,sub);
}
if (repeat > 0)
{
memcpy(dest,current+strlen(sub),strlen(current+strlen(sub)));
}
else
{
memcpy(dest,string,strlen(string)-strlen(current));
}
printf("%s\n",dest);
return dest;
}




编译出错信息如下
[root@localhost livecore.cc]# gcc trimrstr.c
trimrstr.c: In function `main':
trimrstr.c:11: warning: passing arg 2 of `strcpy' makes pointer from integer without a cast
trimrstr.c: At top level:
trimrstr.c:18: warning: type mismatch with previous implicit declaration
trimrstr.c:11: warning: previous implicit declaration of `trimstr'
trimrstr.c:18: warning: `trimstr' was previously implicitly declared to return `int'
trimrstr.c: In function `trimstr':
trimrstr.c:41: warning: function returns address of local variable


...全文

相关推荐

评论 8
收藏 已收藏
分享
返回顶部
henryluo
C语言 70,039 成员 243,237 内容