enum Dirction{up,down,forward,back,left,right};
void main()
{ enum Direction commands[10]=
{forward,right,forward,right,forward,right,forward,right,forward,right};
int x=0,y=0;
int i=0;
for (i=0;i<10;i++)
{
move (commands[i],&x,&y);
printf("\nPosition[%d]is(%d,%d)",i+1,x,y);
}
}
int move(enum Direction command,int*px,int*py)
{
int nRet=1;
static int x=0,y=0;
switch(command)
{
case left:
x-=1;break;
case right:
x+=1;break;
case forward:
y+=1;break;
case back:
y-=1;break;
default:
nRet=0;break;
}
*px=x;
*py=y;
return nRet;
}
enum Dirction{up,down,forward,back,left,right};
void main()
{ enum Direction commands[10]=
{forward,right,forward,right,forward,right,forward,right,forward,right};
int x=0,y=0;
int i=0;
for (i=0;i<10;i++)
{
move (commands[i],&x,&y);
printf("\nPosition[%d]is(%d,%d)",i+1,x,y);
}
}
int move(enum Direction command,int*px,int*py)
{
int nRet=1;
static int x=0,y=0;
switch(command)
{
case left:
x-=1;break;
case right:
x+=1;break;
case forward:
y+=1;break;
case back:
y-=1;break;
default:
nRet=0;break;
}
*px=x;
*py=y;
return nRet;
}
enum Dirction{up,down,forward,back,left,right};
void main()
{ enum Direction commands[10]=
{forward,right,forward,right,forward,right,forward,right,forward,right};
int x=0,y=0;
int i=0;
for (i=0;i<10;i++)
{
move (commands[i],&x,&y);
printf("\nPosition[%d]is(%d,%d)",i+1,x,y);
}
}
int move(enum Direction command,int*px,int*py)
{
int nRet=1;
static int x=0,y=0;
switch(command)
{
case left:
x-=1;break;
case right:
x+=1;break;
case forward:
y+=1;break;
case back:
y-=1;break;
default:
nRet=0;break;
}
*px=x;
*py=y;
return nRet;
}
編譯時顯示:error: array type has incomplete element type並且提示在第三行的代碼上,求指點如何解決這個問題
是Direction,不是Dirction