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