程序何处有问题,该怎么修改,求教各位大神们。
这段代码有问题,我想了好久,也不知是哪行有问题,请教各位啦!!请问该怎么改?#include<stdio.h>
#include <stdlib.h>
static void _fun( int,int,int** );
void print(FILE *fp, const int a[][7][7] );
int main()
{
int i,j;
int a[27][7][7];//E
int* p=NULL;
FILE *fp;
if ((fp = fopen ("D:\\数组.txt", "a+")) == NULL)
{
printf("打开文件失败\n");
exit(1);
}
for (i=0;i!=27;++i)//F
{
p=a[i][1];
{
for (j=1;j!=8;++j)//G
a[i][0][j-1]=j;
}
_fun(i,~1,&p);
_fun(i,1,&p);
}
print(fp, a);
fclose(fp);
return 0;
}
static void _fun( int k,int n,int** p )
{
if (n>0)
_fun(k/3,n-1,p);
{
int i=9; //H
while (--i)
{
**p=k%3;
++*p;
}
}
if (n<0)
_fun(k/3,n+1,p);
}
void print(FILE *fp, const int a[][7][7] )//I
{
int i;
for (i=0;i!=27;++i)//J
{
int j;
fprintf(fp,"i = %d\n",i);
for (j=0;j!=7;++j)//K
{
int k;
for (k=0;k!=7;++k)//L
fprintf(fp,"%-4d",a[i][j][k]);
fprintf(fp,"\n");
}
fprintf(fp,"\n");
}
}
要求:运行后要达到这样的效果:
i = 0
1 2 3 4 5 6 7
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
i = 1
1 2 3 4 5 6 7
1 1 1 1 1 1 1
1 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
1 1 1 1 1 1 1
i = 2
1 2 3 4 5 6 7
2 2 2 2 2 2 2
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
2 2 2 2 2 2 2
i = 3
1 2 3 4 5 6 7
0 0 0 0 0 0 0
1 1 1 1 1 1 1
1 1 0 0 0 0 0
0 0 0 0 0 0 0
1 1 1 1 1 1 1
0 0 0 0 0 0 0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