主题:求助 高手帮忙找找错
我用C写了个很简单的程序,VC提示有问题,可是代码是对的。
#include<stdio.h>
#define M 6
#define N 6
#define MaxSize 100
int mg[M+1][N+1]={
{1,1,1,1,1,1},
{1,0,0,0,1,1},
{1,0,1,0,0,1},
{1,0,0,0,1,1},
{1,1,0,0,0,1},
{1,1,1,1,1,1}
};
struct
{
int i; int j; int di;
} Stack[MaxSize],Path[MaxSize];
int top=-1;
int count=1;
int minlen=MaxSize;
void mgpath()
{
int i,j,di,find,k;
top++;Stack[top].i=1; Stack[top].j=1; Stack[top].di=-1; mg[1][1]=-1;
while(top>-1)
{
i=Stack[top].i; j=Stack[top].j; di=Stack[top].di;
if (i==M-2&&j==N-2)
{
printf(" %4d: ",count++);
for (k=0;k<=top;k++)
{
printf("(%d,%d) ",Stack[k].i,Stack[k].j);
if((k+1)%5==0)printf("\n\t");
}
printf("\n");
if (top+1<minlen)
{
for (k=0;k<=top;k++)
Path[k]=Stack[k];
minlen =top+1;
}
mg[Stack[top].i][Stack[top].j]=0;
top--;
i=Stack[top].i;j=Stack[top].i;di=Stack[top].di;
}
find=0;
while(di<4&&find==0)
{ di++;
switch(di)
{
case 0:i=Stack[top].i-1;j=Stack[top].j;break;
case 1:i=Stack[top].i;j=Stack[top].j+1;break;
case 2:i=Stack[top].i+1;j=Stack[top].j;break;
case 3:i=Stack[top].i;j=Stack[top].j-1;break;
}
if (mg[i][j]==0) find=1;
}
if(find==1)
{ Stack[top].di=di;
top++;
Stack[top].i=i;
Stack[top].j=j;
Stack[top].di=-1;
mg[i][j]=-1;
}
else
{
mg[Stack[top].i][Stack[top].j]=0;
top--;
}
}
printf("最短路径如下:\n");
printf("长度: %d\n",minlen);
printf("路径: ");
for (k=0;k<minlen;k++)
{
printf("(%d,%d) ",Path[k].i,Path[k].j);
if((k+1)%5==0) printf("\n\t");
}
printf("\n");
}
void main()
{
printf("迷宫所有路径如下: \n");
mgpath();
}
问题描述:Linking...
exp.obj : error LNK2001: unresolved external symbol "int __cdecl printf(char const *,...)" (?printf@@YAHPBDZZ)
Debug/124.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.
124.exe - 2 error(s), 0 warning(s)
#include<stdio.h>
#define M 6
#define N 6
#define MaxSize 100
int mg[M+1][N+1]={
{1,1,1,1,1,1},
{1,0,0,0,1,1},
{1,0,1,0,0,1},
{1,0,0,0,1,1},
{1,1,0,0,0,1},
{1,1,1,1,1,1}
};
struct
{
int i; int j; int di;
} Stack[MaxSize],Path[MaxSize];
int top=-1;
int count=1;
int minlen=MaxSize;
void mgpath()
{
int i,j,di,find,k;
top++;Stack[top].i=1; Stack[top].j=1; Stack[top].di=-1; mg[1][1]=-1;
while(top>-1)
{
i=Stack[top].i; j=Stack[top].j; di=Stack[top].di;
if (i==M-2&&j==N-2)
{
printf(" %4d: ",count++);
for (k=0;k<=top;k++)
{
printf("(%d,%d) ",Stack[k].i,Stack[k].j);
if((k+1)%5==0)printf("\n\t");
}
printf("\n");
if (top+1<minlen)
{
for (k=0;k<=top;k++)
Path[k]=Stack[k];
minlen =top+1;
}
mg[Stack[top].i][Stack[top].j]=0;
top--;
i=Stack[top].i;j=Stack[top].i;di=Stack[top].di;
}
find=0;
while(di<4&&find==0)
{ di++;
switch(di)
{
case 0:i=Stack[top].i-1;j=Stack[top].j;break;
case 1:i=Stack[top].i;j=Stack[top].j+1;break;
case 2:i=Stack[top].i+1;j=Stack[top].j;break;
case 3:i=Stack[top].i;j=Stack[top].j-1;break;
}
if (mg[i][j]==0) find=1;
}
if(find==1)
{ Stack[top].di=di;
top++;
Stack[top].i=i;
Stack[top].j=j;
Stack[top].di=-1;
mg[i][j]=-1;
}
else
{
mg[Stack[top].i][Stack[top].j]=0;
top--;
}
}
printf("最短路径如下:\n");
printf("长度: %d\n",minlen);
printf("路径: ");
for (k=0;k<minlen;k++)
{
printf("(%d,%d) ",Path[k].i,Path[k].j);
if((k+1)%5==0) printf("\n\t");
}
printf("\n");
}
void main()
{
printf("迷宫所有路径如下: \n");
mgpath();
}
问题描述:Linking...
exp.obj : error LNK2001: unresolved external symbol "int __cdecl printf(char const *,...)" (?printf@@YAHPBDZZ)
Debug/124.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.
124.exe - 2 error(s), 0 warning(s)