我一直在尝试编译这个程序,但我一直想出错误:“预期的')'在'['令牌”之前靠近声明function1的底部..我在那里的代码对我来说看起来不错所以我我不太确定发生了什么..请对此有所了解,我几乎是 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);
}