c-warning:函数的隐式声明和未定义的引用



我需要写一个函数,在字符串中搜索abc中的一系列字母(而不是数字(,去掉它们,只留下序列的前两个和后两个。例如,如果输入字符串为:dabcemoqmnopqrrtaduvwxaz,则输出应为:da cemoqm rrtadu xaz或者输入是:dabceLMNOpQrstuv567zyx,输出是:da-cefL-OpQr-v567zyx。

我有一个主文件abc.c和abc_functions.c.

我得到一些错误-

abc.c: In function ‘main’:
abc.c:10:5: warning: implicit declaration of function ‘abc_functions’ [-Wimplicit-function-declaration]
abc_functions(str);
^
/tmp/ccmsgqvg.o: In function `main':
abc.c:(.text+0x5f): undefined reference to `abc_functions'
collect2: error: ld returned 1 exit status

有什么想法吗?

`

#include "shortend_string.h"
#include <string.h>
void abc_functions (char str[])
{
char str[max_size];

char *dst = str; 
int j = 0; 
int i;
int curr;
for (i=0; i < strlen(str); i++) 
{

if ((str[i] >= 'a' && str[i] <= 'z') || (str[i] >= 'A' && str[i] <= 'Z')) /*checking that the sequences involves the abc letters only*/
{
for (curr = i; curr < strlen(str); curr++)
{

if (str[curr+1] != str[curr]+1)/* sequences ending point*/
break;
}
}
if (curr >= i+2) /*if sequences is larger than or equal to 2 modify the string*/

{

dst[j++] = str[i]; 
dst[j++] = '-';
dst[j++] = str[curr];
i = curr; /*resetting the loop*/

}
else
dst[j++] = str[i];
}
dst[j] = '';
return(0);
}

`

`

#include <stdio.h>
#include "abc_functions.h"
int main()
{
char str[max_size];
printf("please enter a string:");
fgets(str, max_size, stdin);
printf("nThe String is:%s", str);
abc_functions(str);
printf("nThe output is :%sn" , str);
return 0;
}

`

注意第一个错误:

implicit declaration of function ‘abc_functions’

编译器说您缺少abc_functions((声明。请检查:

  1. abc_functions.h包含正确的解密
  2. abc_functions.h基本目录提供给编译器(使用-Ipath_to_dir(

此外,无论何时询问编译失败,最好提供编译命令行。

最新更新