is not a function or function pointer"?-6ren"> is not a function or function pointer"?-似乎函数 qwertyInches() 应该可以工作但是当我在 main() 中调用它时它给了我 [Error] called object 'qwertyInches' is not a funct-6ren">
gpt4 book ai didi

c - 为什么调用此函数会产生错误 " is not a function or function pointer"?

转载 作者:太空宇宙 更新时间:2023-11-04 00:35:35 27 4
gpt4 key购买 nike

似乎函数 qwertyInches() 应该可以工作但是当我在 main() 中调用它时它给了我

[Error] called object 'qwertyInches' is not a function or function pointer.

如有任何帮助,我们将不胜感激。

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
// Global constant
const int MAX_LENGTH = 81; // global constant for max input line length


void qwertyInches (char row[], double *inches, int x, double y) {
int d;
for (d = 0; d < strlen(row); d++) {
if (x == row[d]) {
*inches = *inches + y;
}
}
}


int main() {
int count[256] = { 0 };
int letterCounter = 0;
int qwertyCounter = 0;
int homeRowCounter = 0;
int dvorakCounter = 0;
char qwertyHomeRow[23] = {"asdfghjkl;ASDFGHJKL:\"'" };
char dvorakHomeRow[22] = {"aoeuidhtns-_AOEUIDHTNS"};
double percentOfCharQwerty = 0.0;
double percentOfCharDvorak = 0.0;
char qwertyHomeRowInches[4] = {"ghGH"};
char qwertyRowInches[46] = {"qweruiopQWERUIOP{[}]\ZzXx|CcVvNnMm<,>./?"};
char qwertyNumberInches[25]= {"`~1!2@3#4$5%7&8*9(0)-_=+)"};
char qwertyTAndYInches[4] = {"TtYy"};
char num6Inches[2] = {"6^"};
char dvorakHomeRowInches[4]= {"iIDd"};
char dvorakRowInches[41] = {"\"<',.>PpGgCcRrLl?/:+=|:;QqJjKkBb\MmWwVvZz"};
char dvorakYandFInches[4] = {"YyFf"};
char dvorakNumberInches [25] = {"~`1!2@3#4$5%7&8*9()0{[]}"};
double dvorakInches = 0.0;
double qwertyInches = 0.0;


/* loop counters */
int k;
int l;
int d;
/* file handle --- in this case I am parsing this source code */
FILE *fp = fopen("newsample.txt", "r");

/* a holder for each character (stored as int) */
int c;

/* for as long as we can get characters... */
while((c=fgetc(fp))) {

/* break if end of file */
if(c == EOF) {
break;
}
else if (c == 32 || c == 10 || c == 9) {
count[c]+=1;
}
/* otherwise add one to the count of that particular character */
else {
count[c]+=1;
letterCounter++;
for (l = 0; l < strlen(dvorakHomeRow); l++) {
if (c == qwertyHomeRow[l]) {
qwertyCounter++;
}
if (c == dvorakHomeRow[l]) {
dvorakCounter++;
}
}
qwertyInches(strlen(qwertyHomeRowInches) , &qwertyInches, c, .75 );

}

}


percentOfCharQwerty = (double) qwertyCounter / (double) letterCounter * 100;
percentOfCharDvorak = (double) dvorakCounter / (double) letterCounter * 100;

printf("Amount of Letters: %d\n", letterCounter);
printf("qwerty counter: %d\n", qwertyCounter);
printf("Dvorak counter: %d\n", dvorakCounter);
printf("Percent of qwerty letters %.2lf\n", percentOfCharQwerty);
printf("Percent of Dvorak letters %.2lf\n", percentOfCharDvorak);
printf("qwertyInches: %.2lf\n", qwertyInches);
printf("dvorakInches: %.2lf\n", dvorakInches);
/* close the file */
fclose(fp);
return;
}

最佳答案

main() 中有一个 qwertyInches 局部变量,它隐藏了 qwertyInches() 函数。

引用 C11,第 6.2.1 章,标识符范围(强调我的)

[....] If an identifier designates two different entities in the same name space, the scopes might overlap. If so, the scope of one entity (the inner scope) will end strictly before the scope of the other entity (the outer scope). Within the inner scope, the identifier designates the entity declared in the inner scope; the entity declared in the outer scope is hidden (and not visible) within the inner scope.

解决方案:更改其中一个名称。

也就是说,qwertyInches() 函数的第一个参数应该是 char *,但是您传递的是 size_t(输出strlen()) 这是完全错误的。也改变它。

关于c - 为什么调用此函数会产生错误 "<function> is not a function or function pointer"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39562693/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com