trouble

I'm trying to write a program that uses a two - dimensional array to find the numbers that are larger than all their neighbors. But I'm having troubles comparing the numbers to their neighbors and my program is not printing our anything. please help.

/* This program uses multidimensional arrays to find the largest
* number compared to their neighbors. I call this program multidimensional.c */

#include <stdio.h> /* librarys */
#include "genlib.h"

#define size 3 /* constants */

void displayMatrix(int intArray [size][size]);
main()
{
/* the intArray values you may change the values is you wish */
int intArray[size][size]=
{
{22,9,1},
{12,8,3},
{4,0,12}
};
}
void displayMatrix(int intArray [size][size])
{
int row, column, x;
int num[size];
x=0;
getchar();
}


Last edited on
I'm only going to say it once because I've said it to someone else too many times: CODE TAGS. Read the articles if you don't know what I'm talking about.
Now then, first of all the compiler, no matter what variables you put into the subscript, does not care what size array you pass to it. Only a template has that ability to discern the size of an array. If you intend to control the size of an array you must pass it by reference. Therefore this is useless:
(int intArray [size][size]);
Size does not exist. Period. You are therefore referring to a nonexistent variable. First read this: http://www.cplusplus.com/doc/tutorial/arrays/ which covers passing normal arrays.
Then read this: http://www.cplusplus.com/forum/articles/17108/ which explains how to pass MD arrays and why they should not be used.
so your saying that i need to define each size instead of using one constant. and that i shouldn't use a matrix?
Let me clarify.
You cannot choose to pass an array of a certain size or ascertain the size thereof in the process of passing it. So when you put size in those subscripts it means nothing and just creates compilation errors when you refer to it. You must pass the size *separately* unless you pass by reference, in which case the compiler can restrict the size that is passed in. And I did not say you should not use an md array. I'm trying to explain how to use one and I'm showing you the caveats of using one. This is why you'd be better off passing an array by its pointer. Do it like people pass STL containers - pass a pointer to the beginning and the end.
so i shouldn't make a new function and just clarify the size of the array separately inside of main() instead of using a constant? sorry if i don't understand you I'm sort of a newbie to md arrays :D
Last edited on
Topic archived. No new replies allowed.