hey guys so i have a program that works, but now I am trying to get function1() to work. What it has to do is bring in the array and populate it with random letters. I don't know much about functions, so I am kind of clueless about the errors that I am getting..
Code:
#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[][]);
void function4(int, int); //function to display the pairs count
int main( void )
{ // MARKS THE BEGINNING OF THE main( ) BLOCK OF STATEMENTS
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];
char array[x][y];
/*
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");
*/
function1(array[x][y]);
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++;
}
}
}
//calls function4 to display the countX and countY
function4 (countX, countY);
return ( 0 ) ;
}
char function1(array[x][y])
{
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);
}
the errors when i compile:
Code:
test.c:8 error: array type has incomplete element type
test.c: In function 'main':
test.c:23: error: redeclaration of 'array' with no linkage
test.c.22: error: previous declaration of 'array' was here
test.c.37: error: type of formal parameter 1 is incomplete
test.c: At top level:
test.c:71 error: expected ')' before '[' token