typedef struct
{
        int x, y, d;
}DataType;DataType temp;temp={x, y, d};这样子为什么提示我 error C2059: syntax error : '{而我如果这样子
temp.x = x;
temp.y = y;
temp.d = d;
是可以运行的为什么呢?
我记得课本上temp={x, y, d};这样子是可以的啊,why?

解决方案 »

  1.   

    syntax error:语法错误
    temp={x, y, d};
    没有这种初始化方式
      

  2.   

    你的课本写的应该是这样吧:
    temp={1,2,3};
    上面这个是可以的,这个是结构体的初始化,但是你上面是赋值,这么写就是错误的。
      

  3.   

    呵呵,应该写成DataType temp = {x, y, d};不能写成两行。
      

  4.   


    我的x,y,d是赋值了的,按照你这样来说应该是可以的啊?
    x=temp.x;
    y=temp.y;
    d=temp.d+1;
      

  5.   

    我的x,y,d是赋值了的,按照你这样来说应该是可以的啊?
    x=temp.x;
    y=temp.y;
    d=temp.d+1;
    =========
    你到底是给谁赋值啊?
    我上面的意思是说:
    DataType temp={1,2,3};这样写是可以的,这是初始化。
    但是:temp={x, y, d};这样写是不行的。没有这样给结构体赋值的。
      

  6.   


    呼呼~~明白了,我发现了《数据结构c语言版》上面的一个大错误了它的源程序是这样子的:#include <stdio.h>
    #include <stdlib.h>#define MAXSIZE 50
    #define m 6
    #define n 8typedef struct
    {
    int x, y, d;
    }DataType;typedef struct  
    {
    DataType data[MAXSIZE];
    int top;
    }SeqStack, *PSeqStack;typedef struct
    {
    int x, y;
    }item;PSeqStack Init_SeqStack(void)
    {
    PSeqStack S;
    S=(PSeqStack)malloc(sizeof(SeqStack));
    if (S)
    {
    S->top=-1;
    }
    return S;
    }void Destroy_SeqStack(PSeqStack *SeqStackPoint)
    {
    if (*SeqStackPoint)
    {
    free(*SeqStackPoint);
    }
    *SeqStackPoint=NULL;
    return;
    }int Empty_SeqStack(PSeqStack S)
    {
    if (-1==S->top)
    {
    return 1;

    else
    {
    return 0;
    }
    }int Push_SeqStack(PSeqStack S, DataType x)
    {
    if (MAXSIZE-1==S->top)
    {
    return 0;
    }
    else
    {
    S->top++;
    S->data[S->top]=x;
    return 1;
    }
    }int Pop_SeqStack(PSeqStack S, DataType *x)
    {
    if (Empty_SeqStack(S))
    {
    return 0;

    else
    {
    *x=S->data[S->top];
    S->top--;
    return 1;
    }
    }int mazepath(int maze[m+2][n+2], item *move, int x0, int y0)
    {
    PSeqStack S;
    DataType temp;
    int x, y, i, j, d;
    temp.x=x0;
    temp.y=y0;
    temp.d=-1;
    S=Init_SeqStack();
    if (!S)
    {
    printf("初始化失败!\n");
    return 0;
    }
    Push_SeqStack(S, temp); while (!Empty_SeqStack(S))
    {
    Pop_SeqStack(S, &temp);
    x=temp.x;
    y=temp.y;
    d=temp.d+1;
    maze[x][y]=0;
    while (d<4)
    {
    i=x+move[d].x;
    j=y+move[d].y;
    if (0==maze[i][j])
    {
    //  temp.x = x;
    //  temp.y = y;
    //  temp.d = d;我加的
    temp={x, y, d};
    Push_SeqStack(S,temp);
    x=i;
    y=j;
    maze[i][j]=-1;
    if (x==m&&y==n)
    {
    //  temp.x = x;
    //  temp.y = y;
    //  temp.d = d;
    //  Push_SeqStack(S,temp);我加的
    while (!Empty_SeqStack(S))
    {
    Pop_SeqStack(S, &temp);
    printf("[%d, %d]<-", temp.x, temp.y);
    }
    Destroy_SeqStack(&S);
    return 1;
    }
    else
    {
    d=0;
    }
    }
    else
    {
    d++;
    }
    }
    }
    Destroy_SeqStack(&S);
    return 0;
    }int main(int argc, char* argv[])
    {
    int x0, y0;
    int maze[m+2][n+2]={1,1,1,1,1,1,1,1,1,1,
    1,0,1,1,1,0,1,1,1,1,
    1,0,0,0,0,1,1,1,1,1,
    1,0,1,0,0,0,0,0,1,1,
    1,0,1,1,1,0,0,1,1,1,
    1,1,0,0,1,1,0,0,0,1,
    1,0,1,1,0,0,1,1,0,1,
    1,1,1,1,1,1,1,1,1,1}; item move[4]={{0,1},{1,0},{0,-1},{-1,0}}; printf("Enter x0 and y0: \n");
    scanf("%d%d", &x0,&y0); mazepath(maze, move, x0, y0); printf("\n"); return 0;
    }