简体   繁体   English

参数过多-具有int参数的函数

[英]too many arguments - function with int argument

This code is the part of the program, which checks the row of a 3x3 Matrix. 该代码是程序的一部分,该程序检查3x3矩阵的行。 The Values for the matrix as 'matrix[row][col]' and N as '3' is previously defined. 矩阵的值预先定义为“ matrix [row] [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函数中只有1个参数“行”,为什么编译器会给出有关参数数量的错误?

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 原型应更改

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_rowmain ,而不用担心需要一个单独的声明。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM