Want to return to the index of the maximum two-dimensional array, the program crashes unfortunately ^ _ ^!

Category: C/C++ -> C Author: maximoking Date: 2005-01-01 11:04:10
 
maximoking
2005-01-01 11:04:10
Where is the problem? And I found written in the Dev-c + + program in a mistake he checked out, a run worth it collapsed!
/ / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
# include <stdio.h>

int main ()
{
int i, j, k;
int a [3] [5];
void receive (int a, int b, int c);
void position ();
int max ();
; printf ("========== please input 3 * 5 numbers =============== \ n");
receive (5,3, a [3] [5]);
printf ("The max number is: \ n");
k = max (3, a [3] [5]);
printf ("% d \ t", k);
printf (" \ n ");
printf (" The index is: \ n ");
position (5,3, a [3] [5]) ;
system ("pause");
return 0;
}
void receive (int m, int n, int b [n] [m]) {
int i, j, k;
for (i = 0; i <n; i + +) {
for (j = 0; j <m; j + +) {
; scanf ("% d", & b [i] [j]);
}
}
}
int max (int n, int ; b [n] [5]) {
int j, i, k;
int * p;
p = & b [0] [0];
for (i = 0; i <n; i + +) {
for (j = 0; j <5; j + +) {
if (* p <b [i] [j])
p = & b [i] [j];
}
}
return * p;
}
void position (int n, int b [n] [5]) {
int j = 0, i = 0, k;
int * p;
p = & b [0] [0];
for (i = 0; i <n; i + +) {
for (j = 0; j <5; j + +) {
if (* p <b [i] [j])
; p = & b [i] [j];
;}
}
printf (" ; i =% d \ t ", i);
printf (" j =% d \ n ", j);
;}
return max no problem! Is to run to the position function problems!
Roby527
2005-01-01 11:08:48
did not apply for the p memory
zw20081112
2005-01-01 11:21:21
Sorry, just a few hasty conclusions under the call parameters
errors are not
dindkai
2005-01-01 11:41:21
not the reasons for it, Why return the maximum value is right? !
dzx907472870
2005-01-01 11:48:31
invoked changed: "position (5,3, a);" or not!
leeruizhong
2005-01-01 12:07:39
advance! In the end they do wrong? : (
clx251963055
2005-01-01 12:10:59
Halo
~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~

int max (int ** arr, int row, int col) / * row: row col: column * /
{
int i;
int j;
int rw;
int cl;

int mx = ** arr ;/ * a [0] [0] * /
rw = cl = 0;
assert (arr! = NULL);
for (i = 0; i <row; i + +)
{
for (j = 0; j <col; j + +)
{
if ( mx <arr [i] [j])
{
mx = arr [i] [j];
rw = i;
cl = j;
} / * if * /
} / * for j * /
} / * for i * /
printf ("max number's position is row: % d col:% d \ n ", row, col);
return mx;
} / * max () * /

can be invoked:
int a [3] [5];
int max;
/ * ... * /
; max = max (a, 3,5);

lele1001
2005-01-01 12:22:10
Why use pointers to pointers? not necessary to: (
UMLsystem
2005-01-01 12:36:53
pointers and arrays are not used as such
int a [3] [5];

/ / receive (5,3, a [3] [5]); ;/ / Error
receive (5,3, a); / / void receive (int m, int n, int b [n] [m])