#include <stdio.h>
#include <stdlib.h>
struct node{
int data;
struct node *next;
};
void printList(struct node *head);
int main() {
struct node* head;
head->data =10;
head->next = NULL;
printList(head);
}
void printList(struct node *head){
struct node *ptr = head;
if (ptr->next = NULL){
printf("list is empty");
}
while(ptr != NULL){
printf("%d", ptr->data);
ptr = ptr->next;
}
}
I'm try to implement a simple list structure, but I am getting a segmentation error.
Any clues to why?
head->data = 10;: ask yourself the question: where doesheadpoint to? Did you read the chapter dealing with pointers and dynamic memory allocation in your learning material?