My code:
#include <stdio.h>
node * create(int);
void disp(node *,int);
typedef struct node
{
int data;
struct node *next;
};
node * create(int);
void disp(node *,int);
typedef struct node *head , *p , *c;
int i,n;
int main()
{
printf("\n Enter the number of nodes:");
scanf("%d",&n);
c=create(n);
disp(head,n);
return 0;
}
node * create(int n)
{
head = (node *)malloc(sizeof(node));
scanf("%d", &head->data);
head->next = NULL;
p=head;
for(i=1;i<n;i++)
{
p=(node*)malloc(sizeof(node));
scanf("%d",&p->data);
p=p->next;
p->next=NULL;
}
return head;
}
void disp(node *head , int n)
{
p=head;
while(p!=NULL)
{
for(i=0;i<n;i++)
{
printf("%d",p->data);
p=p->next;
}
}
}
OUTPUT:
User@Sujata:~/Desktop]$ gcc ll.c
ll.c:3: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
ll.c:4: error: expected ‘)’ before ‘*’ token
ll.c:10: warning: useless storage class specifier in empty declaration
ll.c:11: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
ll.c:12: error: expected ‘)’ before ‘*’ token
ll.c: In function ‘main’:
ll.c:19: error: expected identifier or ‘(’ before ‘=’ token
ll.c:20: error: expected expression before ‘head’
ll.c: At top level:
ll.c:24: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
ll.c:41: error: expected ‘)’ before ‘*’ token
Got this output . Tried many times using the typedef keyword also. But does not work . Thanks in advance !