永发信息网

Error executing link.exe.?

答案:1  悬赏:50  手机版
解决时间 2021-03-10 07:58
  • 提问者网友:最美的风景
  • 2021-03-09 15:07
编写一个函数,输入一行字符,输出最长的单词
#include<stdio.H>
#include<string.H>
main()
{int alphabetic(char);
int longest(char []);
int i;
char line[100];
printf("input one line");
gets(line);
printf("the longest word is:");
for(i=longest(line);alphabetic(line[i]);i++)
printf("%c",line[i]);
}

int alphabetic(char c)
{if((c>='a'&&c<='z')||(c>='A'&&c<='Z'))
return(1);
else
return(0);
}

int longest(char string[])
{int alphabetic(char c);
int i,length=0,len=0,place,inaword=0;
for(i=0;i<=strlen(string);i++)
{if(alpabetic(string[i]))
{inaword=1;
place=i;
len++;}
else
{inaword=0;
if(length<len)
{length=len;
place=i;
len=0;
}
}
}
return(place);
}

连接时显示
Linking...
c.obj : error LNK2001: unresolved external symbol _alpabetic
Debug/c.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.

c.exe - 2 error(s), 0 warning(s)

请问我的算法有问题吗?
一楼的方法没有用。我试过了
最佳答案
  • 五星知识达人网友:我住北渡口
  • 2021-03-09 16:14
#include <stdio.H>
#include <string.H>

int alphabetic(char);
int longest(char []);

main()
{
int i;
char line[100];
printf("input one line");
gets(line);
printf("the longest word is:");
for(i=longest(line);alphabetic(line[i]);i++)
printf("%c",line[i]);
}

int alphabetic(char c)
{if((c>='a'&&c<='z')||(c>='A'&&c<='Z'))
return(1);
else
return(0);
}

int longest(char string[])
{
int i,length=0,len=0,place,inaword=0;
for(i=0;i<=strlen(string);i++)
{if(alphabetic(string[i]))
{inaword=1;
place=i;
len++;}
else
{inaword=0;
if(length<len)
{length=len;
place=i;
len=0;
}
}
}
return(place);
}

修改过了,用MinGW可以编译。成功

E:\office>gcc pa.c -o pa.exe
pa.c:43:2: warning: no newline at end of file
C:\DOCUME~1\LYRAXX~1\LOCALS~1\Temp/ccIlbaaa.o:pa.c:(.text+0x121): undefined refe
rence to `alpabetic'
collect2: ld returned 1 exit status

E:\office>gcc pa.c -o pa.exe
C:\DOCUME~1\LYRAXX~1\LOCALS~1\Temp/cciOaaaa.o:pa.c:(.text+0x121): undefined refe
rence to `alpabetic'
collect2: ld returned 1 exit status

E:\office>gcc pa.c -o pa.exe
C:\DOCUME~1\LYRAXX~1\LOCALS~1\Temp/ccm0baaa.o:pa.c:(.text+0x121): undefined refe
rence to `alpabetic'
collect2: ld returned 1 exit status

E:\office>gcc pa.c -o pa.exe
C:\DOCUME~1\LYRAXX~1\LOCALS~1\Temp/ccQfcaaa.o:pa.c:(.text+0x121): undefined refe
rence to `alpabetic'
collect2: ld returned 1 exit status

E:\office>gcc pa.c -o pa.exe
C:\DOCUME~1\LYRAXX~1\LOCALS~1\Temp/ccE9baaa.o:pa.c:(.text+0x121): undefined refe
rence to `alpabetic'
collect2: ld returned 1 exit status

E:\office>gcc pa.c -o pa.exe
C:\DOCUME~1\LYRAXX~1\LOCALS~1\Temp/ccaicaaa.o:pa.c:(.text+0x121): undefined refe
rence to `alpabetic'
collect2: ld returned 1 exit status

E:\office>gcc pa.c -o pa.exe
pa.c: In function `longest':
pa.c:31: error: syntax error before ')' token
pa.c:35: error: syntax error before "else"
pa.c: At top level:
pa.c:43: error: syntax error before '}' token

E:\office>gcc pa.c -o pa.exe

E:\office>
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯