为什么总是编译错误??compile error
哪位牛人帮忙看看是出了什么问题,为什么下面的程序我用自己的VC6.0编译通过了,在北大ACM网上却总说CompileErrorMain.cppMain.obj:error...
哪位牛人帮忙看看是出了什么问题,为什么下面的程序我用自己的VC6.0编译通过了,在北大ACM网上却总说Compile Error
Main.cpp
Main.obj : error LNK2019: unresolved external symbol _strrev referenced in function "int __cdecl searchmaxsubstring(char *)" (?searchmaxsubstring@@YAHPAD@Z)
Main.exe : fatal error LNK1120: 1 unresolved externals
程序如下:
#include <iostream>
#include <string.h>
using namespace std;
int t,n;
char str[100][101];
int searchmaxsubstring(char source[101])
{
int substrle=strlen(source),sourcestrlen=strlen(source);
int i,j;
bool foundmaxsubstr;
char substr[101],revsubstr[101];
while(substrle>0)
{
for(i=0;i<=sourcestrlen-substrle;i++)
{
strncpy(substr,source+i,substrle);
strncpy(revsubstr,source+i,substrle);
substr[substrle]=revsubstr[substrle]='\0';
strrev(revsubstr);
foundmaxsubstr=true;
for(j=0;j<n;j++)
if(strstr(str[j],substr)==NULL&&strstr(str[j],revsubstr)==NULL)
{
foundmaxsubstr=false;
break;
}
if(foundmaxsubstr)
return(substrle);
}
substrle--;
}
return 0;
}
int main()
{
int searchmaxsubstring(char source[101]);
int i,minstrlen=0,substrlen=0;
char minstr[101];
cin>>t;
while(t--)
{
cin>>n;
minstrlen=100;
for(i=0;i<n;i++)
{
cin>>str[i];
if(strlen(str[i])<minstrlen)
{
strcpy(minstr,str[i]);
minstrlen=strlen(minstr);
}
}
substrlen=searchmaxsubstring(minstr);
cout<<substrlen<<endl;
}
return 0;
}
非常感谢深绿青蓝,但是把main()里面的声明函数去掉还是不行哦...到底是为什么呢... 展开
Main.cpp
Main.obj : error LNK2019: unresolved external symbol _strrev referenced in function "int __cdecl searchmaxsubstring(char *)" (?searchmaxsubstring@@YAHPAD@Z)
Main.exe : fatal error LNK1120: 1 unresolved externals
程序如下:
#include <iostream>
#include <string.h>
using namespace std;
int t,n;
char str[100][101];
int searchmaxsubstring(char source[101])
{
int substrle=strlen(source),sourcestrlen=strlen(source);
int i,j;
bool foundmaxsubstr;
char substr[101],revsubstr[101];
while(substrle>0)
{
for(i=0;i<=sourcestrlen-substrle;i++)
{
strncpy(substr,source+i,substrle);
strncpy(revsubstr,source+i,substrle);
substr[substrle]=revsubstr[substrle]='\0';
strrev(revsubstr);
foundmaxsubstr=true;
for(j=0;j<n;j++)
if(strstr(str[j],substr)==NULL&&strstr(str[j],revsubstr)==NULL)
{
foundmaxsubstr=false;
break;
}
if(foundmaxsubstr)
return(substrle);
}
substrle--;
}
return 0;
}
int main()
{
int searchmaxsubstring(char source[101]);
int i,minstrlen=0,substrlen=0;
char minstr[101];
cin>>t;
while(t--)
{
cin>>n;
minstrlen=100;
for(i=0;i<n;i++)
{
cin>>str[i];
if(strlen(str[i])<minstrlen)
{
strcpy(minstr,str[i]);
minstrlen=strlen(minstr);
}
}
substrlen=searchmaxsubstring(minstr);
cout<<substrlen<<endl;
}
return 0;
}
非常感谢深绿青蓝,但是把main()里面的声明函数去掉还是不行哦...到底是为什么呢... 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询