失踪 ';'在'类型'之前

时间:2011-04-17 13:34:59

标签: c

#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

2 个答案:

答案 0 :(得分:7)

int main()
{
    node *head;
    head = createList();
    void printList(node *head); // This isn't how you call a function
    return 0;
}

更改为:

int main()
{
    node *head;
    head = createList();
    printList(head); // This is.
    return 0;
}

答案 1 :(得分:2)

main()中的这一行是你的问题:

void printList(node *head);

应该是:

printList(head);

你想在那里调用函数,而不是试图声明它。