#include <stdio.h>
#include <stdlib.h>
typedef struct student {
int rollNo;
char studentName[25];
struct student *next;
}node;
node *createList();
void printList(node *);
int main()
{
node *head;
head = createList();
void printList(node *head);
return 0;
}
node *createList()
{
int idx,n;
node *p,*head;
printf("How many nodes do you want initially?\n");
scanf("%d",&n);
for(idx=0;idx<n;++idx)
{
if(idx == 0)
{
head = (node*)malloc(sizeof(node));
p = head;
}
else
{
p->next = (node*)malloc(sizeof(node));
p = p->next;
}
printf("Enter the data to be stuffed inside the list <Roll No,Name>\n");
scanf("%d %s",&p->rollNo,p->studentName);
}
p->next = NULL;
p = head;
/*while(p)
{
printf("%d %s-->\n",p->rollNo,p->studentName);
p=p->next;
}*/
return(head);
}
void printList(node *head)
{
node *p;
p = head;
while(p)
{
printf("%d %s-->\n",p->rollNo,p->studentName);
p=p->next;
}
}
這裏可能有什麼錯誤?我知道我做了一些愚蠢的事情,只是無法弄清楚它是什麼。 我得到這些錯誤失蹤';'之前輸入'
error C2143: syntax error : missing ';' before 'type'
error C2143: syntax error : missing '{' before '*'
error C2371: 'createList' : redefinition; different basic types
錯誤消息涉及什麼行? – 2011-04-17 13:37:45
這個編譯對我來說很好。 – 2011-04-17 13:39:35
錯誤C2143:語法錯誤:缺少';'在'type'之前>>> >>> printList(node * head); 錯誤C2143:語法錯誤:在'*&錯誤C2371:'createList'之前缺少'{':重新定義;不同的基本類型>>> node * createList() – Kelly 2011-04-17 13:40:55