c - 不知道为什么我在 C 中得到 'conflicting types' 错误和 'implicit declaration error'。

标签 c

我正在编写一个程序来生成一串随机大写字母,然后获取用户输入的大写字母以及用户输入的字符。对于随机字符串中用户输入字母的任何实例,它将用用户输入的字符替换该字母。

例如,s1 = {BDHFKYL} s2 = {YEIGH} c = '*'

输出 = BD*FK*L

无论如何,我在 main 下的函数声明中遇到类型冲突错误,并且我在函数调用中隐式修饰。有谁知道为什么?先感谢您。

#include <stdio.h>
#include <stdlib.h>

void fillS1(char x[42]);

void fillS2(char x[22]);

void strfilter(char a[], char b[], char c);

int main(int argc, const char * argv[])
{
char s1[42];
char s2[22];


fillS1(s1);

//printf("%s\n", s1);

puts(s1);

fillS2(s2);

strFilter(s1, s2, '*');  //Implicit declaration here


return 0;
}

void fillS1(char x[])
{
for (int i = 0; i < 40; i++)
    x[i] = 'A' + random() % 26;
x[40] = (char)0;
}

void fillS2(char x[]){

int i = 0;


printf("Please enter at least 2 capital letters and a maximum of 20.\n");
while (( x[i] = getchar()) != '\n' ) {

    i++;

    }

x[i] = '\0';

if (i < 3) {
    printf("You need at least two letters");
}

else if (i > 21){
    printf("You cannot have more than twenty letters");
}

/*else if (((i > 'a')) || ((i < 'z'))){
    printf("You many only have capital letters");
}   */



 else puts(x);
}

void strFilter(char a[], char b[], char c){ //Conflicting types error here
int i = 0;
int n = 0;

while (n < 21) {

    for (i = 0; i < 41; i++) {
        if (a[i] == b[n]){
            c = a[i];
        }
    }
    i = 0;
    n++;
}

puts(a);
}

最佳答案

您的标识符不匹配:strFilter(大写 F)与 strfilter(小写 f)。所以,改变你的预先声明:

void strfilter(char a[], char b[], char c);

为此:

void strFilter(char a[], char b[], char c);

关于c - 不知道为什么我在 C 中得到 'conflicting types' 错误和 'implicit declaration error'。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12965771/

相关文章:

c - 为什么这个程序会导致段错误?

c - 如何用 Boogie 验证 VCC 生成的 Boogie 程序?

c - 函数返回局部变量的地址,在c中

c - 为什么在为我的敲击中的字符串分配内存后会出现 0xCCCCCCCC 错误?

c - 在c中输入 float 时如何进行错误检查?

C : memcpy to the "end" of a buffer

c - 理解c中两个链表实现之间的区别

c - 在 C 程序中跟踪数组越界访问/写入的推荐方法

c++ - 如何使用 Windows API 检索 HD 供应商/序列号

c - 如何在字符串数组上使用二分查找