Reputation: 213
#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
Upvotes: 0
Views: 7170
Reputation: 13946
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.
Upvotes: 2
Reputation: 91270
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;
}
Upvotes: 7