I’m an absolutely newbie to both this site and programming so please be patient with me. I decided to start learning programming by learning C. Now, I still know nothing outside of stdio.h . Anyway, I’ve now come across a new topic, which is function and I would like to try using it to do something.
However, I’ve never got the chance to know whether my algorithm is right or not
due to the errors while compiling and I really don’t understand what the
compiler’s error message is trying to tell me. I don’t know what caused the errors.
Therefore, I need someone to have a look at my code and guide/explain/teach me,
anything.
I’m trying to print out X and O in chessboard manner by using a function and here’s
my code.
int function_X;
int function_O;
int size_controller;
main()
{
int i;
int j;
int width;
int height;
clrscr();
printf("Width: \n");
scanf("%d", &width);
printf("Height: \n");
scanf("%d", &height);
for(j=0; j<height; j++)
{
for(i=0; i<width; i++)
{
if(size_controller(i) )
{
printf("\n");
}
if(function_X(i, j) )
{
printf("X");
}
if(function_O(i, j) )
{
printf("O");
}
}
}
return 0;
}
int size_controller(int i)
{
if(i%width == 0)
{
return 1;
}
else
{
return 0;
}
}
int function_X(int i, int j)
{
if((j%2 != 0) && (i%2 != 0) || (j%2 == 0) && (i%2 == 0))
{
return 1;
}
else
{
return 0;
}
}
int function_O(int i, int j)
{
if((j%2 != 0) && (i%2 == 0) || (j%2 == 0) && (i%2 != 0))
{
return 1;
}
else
{
return 0;
}
}
When I tried to run the program, the compiler declared 7 errors and 1 warning:
Error 01.C 27: Call of nonfunction
Error 01.C 32: Call of nonfunction
Error 01.C 37: Call of nonfunction
Error 01.C 48: Type mismatch in redeclaration of ‘size_controller’
Error 01.C 49: Undefined symbol ‘width’
Warning 01.C 57: Parameter ‘i’ is never used
Error 01.C 60: Type mismatch in redeclaration of ‘function_X’
Error 01.C 72: Type mismatch in redeclaration of ‘function_O’
Please help me!
Change these (which look like ordinary variables):
To these (which look like function declarations):
But the only truly sensible advice is to get hold of a decent book and study, these really are problems you could have avoided.