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