C 为什么调用此函数会产生错误“&书信电报;功能>;不是函数或函数指针;?

C 为什么调用此函数会产生错误“&书信电报;功能>;不是函数或函数指针;?,c,function,scope,function-call,C,Function,Scope,Function Call,似乎函数qwertyInches()应该可以工作,但是当我在main()中调用它时 [错误]调用的对象“qwertyInches”不是函数或函数指针 任何帮助都将不胜感激 #include <stdio.h> #include <stdlib.h> #include <string.h> // Global constant const int MAX_LENGTH = 81; // global constant for max input line l

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

[错误]调用的对象“qwertyInches”不是函数或函数指针

任何帮助都将不胜感激

#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;
}
#包括
#包括
#包括
//全局常数
常量int MAX_LENGTH=81;//最大输入线长度的全局常数
无效QWERTYINCHERS(字符行[],双*英寸,整数x,双y){
int d;
对于(d=0;dchar-dvorakrowiches[41]={“\”您将
qwertyInches
定义为变量和函数

void qwertyInches (char row[], double *inches, int x, double y) {


只需更改上面其中一个的名称。我通常为函数指定一个“操作”名称,为变量指定一个“事物”名称。

您将
qwertyInches
定义为变量和函数

void qwertyInches (char row[], double *inches, int x, double y) {

只需更改上面其中一个的名称,我通常给函数起一个“action”名称,给变量起一个“thing”名称

当我在main中调用它时,它给出了这样一个…[错误]称为对象“qwertyInches”的对象不是函数或函数指针

当然,编译器是正确的。在
main()
中,此声明隐藏了函数声明:

因此,在
main()

void qwertyInches (char row[], double *inches, int x, double y) {
当我在main中调用它时,它给出了这样一个…[错误]称为对象“qwertyInches”的对象不是函数或函数指针

当然,编译器是正确的。在
main()
中,此声明隐藏了函数声明:


因此,在
main()

void qwertyInches (char row[], double *inches, int x, double y) {
引用
C11
,第§6.2.1章,标识符范围(重点)

[…]如果标识符以相同的名称指定两个不同的实体 如果是,则一个实体的作用域(内部作用域)将结束 严格在其他实体的范围之前(外部范围)。在内部范围内 标识符指定在内部范围中声明的实体;在外部范围中声明的实体 范围在内部范围内隐藏(不可见)。

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


这就是说,
qwertyInches()
函数的第一个参数应该是一个
char*
,但是您传递的是一个
size\t
(strlen()
的输出),这是完全错误的。请也更改一下。

qwertyInches
main()
中有一个
qwertyInches
局部变量
功能

void qwertyInches (char row[], double *inches, int x, double y) {
引用
C11
,第§6.2.1章,标识符范围(重点)

[…]如果标识符以相同的名称指定两个不同的实体 如果是,则一个实体的作用域(内部作用域)将结束 严格在其他实体的范围之前(外部范围)。在内部范围内 标识符指定在内部范围中声明的实体;在外部范围中声明的实体 范围在内部范围内隐藏(不可见)。

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


也就是说,
qwertyInches()
函数的第一个参数应该是一个
char*
,但是你传递的是一个
size\u t
(strlen()
的输出),这显然是错误的。也要改变这个参数。

在众多答案中,看起来你传递的参数也是错误的。你有
char行[]
是第一个参数,但是正在传入
strlen(qwertyhomerowinces)
,这是一个int;@MichaelPickett我是说
size\u t
,对吧?@SouravGhosh是的,我是这样做的。我的错误。在众多答案中,似乎您传入了错误的参数。您有
字符行[]
是第一个参数,但是正在传递
strlen(qwertyHomeRowInches)
,这是一个int;@MichaelPickett我想知道你的意思是
大小
,对吧?@SouravGhosh是的,我做了。我错了。