Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
204 views
in Technique[技术] by (71.8m points)

c - warning: implicit declaration of function ‘colcheck’ [-Wimplicit-function-declaration]

I am new to C programming which's why I am confused with its syntax. Question: A Sudoku puzzle uses a 9 × 9 grid in which each column and row, as well as each of the nine 3 × 3 subgrids, must contain all of the digits 1 ? ? ? 9. Figure 4.26 presents an example of a valid Sudoku puzzle. This project consists of designing a multithreaded application that determines whether the solution to a Sudoku puzzle is valid. There are several different ways of multithreading this application. The one suggested strategy is to create threads that check the following criteria: ? A thread to check that each column contains the digits 1 through 9 ? A thread to check that each row contains the digits 1 through 9

#include <stdlib.h>

int i,j,m,b,k;
void main()
{
    int a[9][9]={1,2,3,4,5,6,7,8,9,
                4,5,6,7,8,9,1,2,3,
                7,8,9,1,2,3,4,5,6,
                2,3,4,5,6,7,8,9,1,
                5,6,7,8,9,1,2,3,4,
                8,9,1,2,3,4,5,6,7,
                3,4,5,6,7,8,9,1,2,
                6,7,8,9,1,2,3,4,5,
                9,1,2,3,4,5,6,7,8};
                
                
    if(rowcheck(a)==1 && colcheck(a)==1 & cubecheck(a)==1)
    {
        printf("Success");
    }
    else{
        printf("Failed");
    }
}

int rowcheck(int a[9][9])
{
    int c[10]={0};
    for(i=0;i<9;i++)
    {
        for(j=0;j<9;j++)
        {
            c[a[i][j]]++;
        }
        for(k=1;k<=9;k++)
            if(c[k]!=1)
            {
                printf("The value %d came %d times in %d row 
",k,c[k],i+1);
                return 0;
            }
            for(k=1;k<=9;k++)
                c[k]=0;
    }
    return 1;
}

int colcheck(int a[9][9])
{
    int c[10]={0};
    for(i=0;i<9;i++)
    {
        for(j=0;j<9;j++)
        {
            c[a[i][j]]++;
        }
        for(k=1;k<=9;k++)
            if(c[k]!=1)
            {
                printf("The value %d came %d times in %d column 
",k,c[k],i+1);
                return 0;
            }
            for(k=1;k<=9;k++)
                c[k]=0;
    }
    return 1;
}

int cubecheck(int a[9][9])
{
    int c[10]={0},count=0;
    for(m=0;m<9;m+=3)
    {
        for(b=0;b<9;b+=3)
        {
            for(i=m;i<m+3;i++)
            {
                for(j=b;j<b+3;j++)
                {
                    c[a[i][j]]++;
                }
            }
            count++;
            for(k=1;k<=9;k++)
                if(c[k]!=1)
                {
                    printf("The value %d came %d times in %d box
",k,c[k],count);
                    return 0;
                }
                for(k=1;k<=9;k++)
                    c[k]=0;
        }
    }
    return 1;
}```

I am getting this error plz help.

```proj1.c: In function ‘main’:
proj1.c:18:8: warning: implicit declaration of function ‘rowcheck’ [-Wimplicit-function-declaration]
     if(rowcheck(a)==1 && colcheck(a)==1 & cubecheck(a)==1)
        ^~~~~~~~
proj1.c:18:26: warning: implicit declaration of function ‘colcheck’ [-Wimplicit-function-declaration]
     if(rowcheck(a)==1 && colcheck(a)==1 & cubecheck(a)==1)
                          ^~~~~~~~
proj1.c:18:43: warning: implicit declaration of function ‘cubecheck’ [-Wimplicit-function-declaration]
     if(rowcheck(a)==1 && colcheck(a)==1 & cubecheck(a)==1)
                                           ^~~~~~~~~
proj1.c: At top level:
proj1.c:136:1: error: expected identifier or ‘(’ before ‘}’ token
 }```
 ^


question from:https://stackoverflow.com/questions/65651668/warning-implicit-declaration-of-function-colcheck-wimplicit-function-declar

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You need to give declarations for your functions before main() method since you define them afterwards:. A forward function declaration just tells the compiler that, somewhere in your code, a function with the same name will be defined, in this case after its usage in main().

Usually, in C/C++ you define function prototypes in header files, then include them in your main source code, so the functions can safely be defined after they are called.

#include <stdio.h>
#include <stdlib.h>

// add forward declarations for your functions here
int rowcheck(int [][9]);
int colcheck(int [][9]);
int cubecheck(int [][9]);

int main() {
    // your code
    return 0:
}

// method definitions afterwards

int rowcheck(int a[9][9]) {
    // your definition here
}

int colcheck(int a[9][9]) {
    // your definition here
}

int cubecheck(int a[9][9]) {
    // your definition here
}

Also, define your main method as int main() rather than void main().


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

56.9k users

...