太多的参数-函数与int参数。

时间:2022-01-28 16:00:35

This code is the part of the program, which checks the row of a 3x3 Matrix. The Values for the matrix as 'matrix[row][col]' and N as '3' is previously defined.

这个代码是程序的一部分,它检查一个3x3矩阵的行。矩阵的值为“矩阵[行][col]”,N为“3”。

Compiling the Code gives something like:

编译代码的过程如下:

error_handler.c:20:3: error: too many arguments to function ‘check_row’

The actual code looks like:

实际的代码如下:

#include <stdio.h>
#include "globals.h"

void check_row(void); //Prototype

bool check  (void)
{
int ergebnis_row, ergebnis_col, ergebnis_block;
ergebnis_row = FALSE;
ergebnis_col = FALSE;
ergebnis_block = FALSE;

int row, col;
for (row = 1; row <= N*N; row++)
{
     if (check_row(row) == TRUE)
    {
         ergebnis_row = TRUE;
    }
}

if ((ergebnis_row && ergebnis_col && ergebnis_block) == FALSE)
    return FALSE;
else
    return TRUE;
}



bool check_row (int row)
{
    int tester[9], col, i, truefalse;
truefalse = 1;

for (col = 1; col <=(N*N); col++)
{
    tester[col] = 0; //Initialisierung von tester und temp
}            //


for (col = 1; col <=(N*N); col++)
{
    tester[matrix[row][col]] += 1; //For each number, tester array is increased by 1

}

for (col = 1; col <=(N*N); col++)
{

    if (tester[col] > 1)
    {   
        truefalse--; // If there is an error, truefalse changes
        printf("\nZu viele %d an Reihe %d", (matrix[row][col]), row);
    }

}

if (truefalse == 1)
    return FALSE;
else
    return TRUE;

}

Even though there is only 1 Argument 'row' in the function check_row, why does the compiler give an error about the number of the Arguments?

尽管函数check_row中只有一个参数“row”,但为什么编译器会对参数的数量给出错误?

2 个解决方案

#1


1  

Your function declaration does not match your function call or definition:

函数声明与函数调用或定义不匹配:

void check_row(void); // function declaration, specifies no arguments and no return value
...
if (check_row(row) == TRUE) // function call, passes 1 argument and uses return value
                            // conflicts with declaration
...
bool check_row (int row) // function definition, specifies bool return type and 1 int argument
                         // conflicts with declaration

You can save yourself some headaches by putting the definition of check_row before main, and not worry about needing a separate declaration.

通过将check_row的定义放在main之前,您可以省去一些麻烦,不必担心需要单独声明。

#2


2  

void check_row(void);

should be

应该是

bool check_row (int row);

Your declaration doesn't match the definition change your function declaration. Prototype should be changed

您的声明不符合定义更改您的函数声明。原型应该改变

#1


1  

Your function declaration does not match your function call or definition:

函数声明与函数调用或定义不匹配:

void check_row(void); // function declaration, specifies no arguments and no return value
...
if (check_row(row) == TRUE) // function call, passes 1 argument and uses return value
                            // conflicts with declaration
...
bool check_row (int row) // function definition, specifies bool return type and 1 int argument
                         // conflicts with declaration

You can save yourself some headaches by putting the definition of check_row before main, and not worry about needing a separate declaration.

通过将check_row的定义放在main之前,您可以省去一些麻烦,不必担心需要单独声明。

#2


2  

void check_row(void);

should be

应该是

bool check_row (int row);

Your declaration doesn't match the definition change your function declaration. Prototype should be changed

您的声明不符合定义更改您的函数声明。原型应该改变