#include<stdio.h>
#include<stdlib.h>
struct node {
int data;
int key;
struct node *next,*ptr;
};
struct node *head = NULL;
void input(){
ptr=(struct node *)malloc(sizeof(struct node));
for(int i=0;i<5;i++){
printf("enter the elements");
scanf("%d",&ptr->data);
ptr->key=i;
ptr=ptr->next;
}
void display(){
ptr=head;
while(ptr!=NULL){
printf("the linkedlist is --\n");
printf("%d",ptr->data);
ptr=ptr->next;
}
}
}
void main(){
input();
display();
}
This gives two errors-
- error: 'ptr' undeclared
- warning: implicit declaration of function 'display'
I have declared ptr ,then why is it giving this error? And what about display function? And is my code logic correct to input the elements in a linkedlist and display them?