【问题标题】:-Wimplicit-function declaration in C [closed]-C中的Wimplicit-function声明[关闭]
【发布时间】:2020-04-15 16:34:28
【问题描述】:

我不明白这是如何隐含的,我在每个函数中都返回一个 int,并且它们都在主函数之前。老实说,第一次看到有人给我发了一个很长的代码来调试并且有很多错误但是为什么这不起作用我错过了什么

int findString(char matrix[ROW][COLUNM],char str1[],int length){
    int left,right,top,down,result;



    left=left2_right(matrix,str1,length);-THESE 4 CALLS GIVE THE WARNINGS
    right=rigth2_left(matrix,str1,length);
    top=top_bottom(matrix,str1,length);
    down=bottom_top(matrix,str1,length);

    if(left != -1 ){result=left;}
    if(right != -1 ){result=right;}
    if(top != -1 ){result=top;}
    if(down != -1 ){result=down;}

return result;
}

这是其中一项功能

int left2_right(char matrix[ROW][COLUNM],char str1[],int length){

    int i = 0, j, counting = 0, wordcnt;
    //int length = computeLength(str1);   //returns legth of string   
    int index = -1;

    for (i = 0; i < ROW; i++)
    {
        for (j = 0; j < COLUNM; j += 1)
        {
            if (matrix[i][j] == str1[0])
               {    counting = 0;
                for (wordcnt = 0; wordcnt < length; wordcnt++)
                {
                 if (matrix[i][j + wordcnt] == str1[wordcnt])
                 {
                    counting++;
                 }
             }

            if (counting == length)
            {
                index = (i *12) + j;
            }
        }
    }
}

return index;
}

【问题讨论】:

  • 别担心。无论如何,这些功能很糟糕,应该重写。:)

标签: c arrays function declaration


【解决方案1】:

其他函数位于main 函数之前是不够的。每个函数必须在用于任何其他函数之前出现。您可能在其他 4 个解释警告的函数之前定义了 findString

要么对函数重新排序,以便在它们在其他地方使用之前定义它们,要么在源文件顶部声明函数,这样相对排序就无关紧要了。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-04-23
    • 1970-01-01
    • 2015-12-18
    • 1970-01-01
    • 1970-01-01
    • 2019-10-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多