C语言问题,二维数组回形遍历

输出一直是-858什么的,代表没有数值
检查不出错误来……
谢谢
#include<stdio.h>
#define ROW 100
#define COL 100

int main()
{
int matrix[ROW][COL];
int row,col;
int i,j,k;
int xxrow,sxrow,xxcol,sxcol;
scanf("%d %d",&row,&col);
xxrow=0;
sxrow=row-1;
xxcol=0;
sxcol=col-1;

for(i=0;i<row;i++){
for(j=0;j<col;j++){
scanf("%d",&matrix[row][col]);
}
}
if(row%2==0&&col%2==0){
while((xxrow<sxrow)&&(xxcol<sxcol)){
for(i=xxcol;i<sxcol;i++){
printf("%d\n",matrix[xxrow][i]);
}
for(j=xxrow;j<sxcol;j++){
printf("%d\n",matrix[j][sxcol]);
}
for(i=sxcol;i>xxcol;i--){
printf("%d\n",matrix[sxrow][i]);
}
for(j=sxrow;j>xxrow;j--){
printf("%d\n",matrix[j][xxcol]);
}
xxrow++;
sxrow--;
xxcol++;
sxcol--;
}
}
if((row%2==0)&&(col%2!=0)){
while((xxrow<sxrow)&&(xxcol<sxcol)){
for(i=xxcol;i<sxcol;i++){
printf("%d\n",matrix[xxrow][i]);
}
for(j=xxrow;j<sxcol;j++){
printf("%d\n",matrix[j][sxcol]);
}
for(i=sxcol;i>xxcol;i--){
printf("%d\n",matrix[sxrow][i]);
}
for(j=sxrow;j>xxrow;j--){
printf("%d\n",matrix[j][xxcol]);
}
xxrow++;
sxrow--;
xxcol++;
sxcol--;
}
for(k=xxrow;k<=sxrow;k++){
printf("%d\n",matrix[k][xxcol]);
}
}
if((row%2!=0)&&(col%2==0)){
while((xxrow<sxrow)&&(xxcol<sxcol)){
for(i=xxcol;i<sxcol;i++){
printf("%d\n",matrix[xxrow][i]);
}
for(j=xxrow;j<sxcol;j++){
printf("%d\n",matrix[j][sxcol]);
}
for(i=sxcol;i>xxcol;i--){
printf("%d\n",matrix[sxrow][i]);
}
for(j=sxrow;j>xxrow;j--){
printf("%d\n",matrix[j][xxcol]);
}
xxrow++;
sxrow--;
xxcol++;
sxcol--;
}
for(k=xxcol;k<=sxcol;k++){
printf("%d\n",matrix[xxrow][k]);
}
}
if((row%2!=0)&&(col%2!=0)){
while((xxrow<sxrow)&&(xxcol<sxcol)){
for(i=xxcol;i<sxcol;i++){
printf("%d\n",matrix[xxrow][i]);
}
for(j=xxrow;j<sxcol;j++){
printf("%d\n",matrix[j][sxcol]);
}
for(i=sxcol;i>xxcol;i--){
printf("%d\n",matrix[sxrow][i]);
}
for(j=sxrow;j>xxrow;j--){
printf("%d\n",matrix[j][xxcol]);
}
xxrow++;
sxrow--;
xxcol++;
sxcol--;
}
printf("%d\n",matrix[xxrow][xxcol]);
}
return 0;
}

你贴了一大版出来,头晕。。。。
一眼看去,你的输入就错了
改成&matrix[i][j]
温馨提示:内容为网友见解,仅供参考
第1个回答  2011-11-25
肯定是越界问题,自己找下
相似回答