#include
#include
#include
struct LinkList
{
int data;
struct LinkList next;
};
struct LinkList Reverse ( LinkList *list ) *出錯**
{
LNode *tmp = NULL;
LNode *p = NULL;
if (list == NULL)
{
return NULL;
}
tmp = list->next;
while (tmp->next != NULL)
{
p = tmp->next;
tmp->next = p->next;
p->next = list->next;
list->next = p;
}
return list;
}
int main( )
{
int i=0;
int b;
struct LinkList *L;
struct LinkList *p;
struct LinkList *q;
p=L->next;
while (b!= -1)
{
while( scanf("%d\n",&b)&&(b>0) )
{ p->data=b;
p=p->next;
i++;
}
}
struct LinkList Reverse ( LinkList L ); *出錯**
q=L->next;
while(i>=0)
{
printf("%d\n",q->data);
i--;
}
return 0;
}
為什麼會提示
Main.c:31: error: expected ‘)’ before ‘*’ token
Main.c: In function ‘main’:
Main.c:68: error: expected ‘)’ before ‘*’ token
struct LinkList Reverse ( LinkList L ); 出錯*
q=L->next;//這樣操作不對
因為,你把 LinkList定義為結構體類型,相應的L就是結構體變量
struct LinkList
{
int data;
struct LinkList next;
};
next是結構體L的成員,C語言訪問結構體成員的方式是:L.next;
或者你把L定義為指針變量:LinkList *L,這樣你可以通過->來訪問L指向的結構體的成員L->next。