简体   繁体   中英

missing ';' before 'type'

#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;
    }
}

What could possibly be wrong here? I know i have done something silly, just can't figure out what it is. I am getting these errors

 error C2143: syntax error : missing ';' before 'type'
 error C2143: syntax error : missing '{' before '*'
  error C2371: 'createList' : redefinition; different basic types
int main()
{
    node *head;
    head = createList();
    void printList(node *head); // This isn't how you call a function
    return 0;
}

Change to:

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

This line in main() is your problem:

void printList(node *head);

It should be:

printList(head);

You want to be calling the function there, not trying to declare it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM