如何在'''之前修复“预期')'

时间:2013-11-05 03:33:02

标签: c syntax-error

我一直在尝试编译这个程序,但我不断提出错误: “预期')''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ,我几乎是C的菜鸟,所以请你好..

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


#define maxrow 20  //defines maxrow as a constant of 20
#define maxcol 30  //defines maxcol as a constant of 30


void function1(char array[][maxcol]);
void function4(int, int); //function to display the pairs count


int main( void )
{  



int x = 0;
int y = 0;
int row = 0;
int col = 0;
int countX = 0;
int countY = 0;
srandom( (unsigned) time(NULL) );
char array[maxrow][maxcol];


function1(array);

/*
for (x=0;x<maxrow;x++)
    {
     for (y=0;y<maxcol;y++)
        {
         array[x][y] = random() % 26 + 'A';
         printf("%c ", array[x][y]);
        }
    printf("\n");
    }
printf("\n");
*/


for (row=0;row<maxrow-1;row++)
    {
     for (col=0;col<maxcol; col++)
        {
         if (array[row][col] == array[row+1][col])
           {
            countX++;
           }
        }
    }

for(col=0;col<maxcol-1;col++)
    {
     for (row=0;row<maxrow;row++)
        {
         if (array[row][col] == array[row][col+1])
           {
            countY++;
           }
        }
    }



function4 (countX, countY);


    return ( 0 ) ;

}    // MARKS THE END OF THE main( ) BLOCK OF STATEMENTS

这是错误的地方:

void function1(array[][maxcol])
    {
    int x = 0;
    int y = 0;

     for (x=0;x<maxrow;x++)
        {
             for (y=0;y<maxcol;y++)
                {
                 array[x][y] = random() % 26 + 'A';
                 printf("%c ", array[x][y]);
                }
         printf("\n");
        }
    printf("\n");

    return(array[x][y]);
    }


void function4(int countX, int countY)
    {
    printf("\nNumber of horizontal pairs: %d\n", countX);
    printf("\nNumber of vertical pairs: %d\n\n", countY);

    }    

2 个答案:

答案 0 :(得分:6)

更改

void function1(array[][maxcol])  
         //    ^type missing  

void function1(char array[][maxcol])  

此外,您无法从返回类型为void的函数返回任何内容。声明

 return(array[x][y]);   

不应该在那里。

答案 1 :(得分:0)

为什么在返回类型为void时从function1返回值?如果问题仍然存在,请说明错误发生的确切行。