ragedmonkey
May 30th, 2011, 11:33 PM
Hello, this is my simple attempt to start implementing Linked List.
I am getting a Segmentation Fault at
Line:
newNode->item =d;
Does anyone know why?
#include <assert.h>
#include <sys/types.h>
#include <stdio.h>
struct node{
int item;
struct node *next;
};
struct node* createNode(int d){
struct node *newNode;
newNode->item = d;
//newNode->next = NULL;
return newNode;
}
int main(){
struct node *new = createNode(10);
//int x=0;
//printf("%d\n",new->item);
return 0;
}
I am getting a Segmentation Fault at
Line:
newNode->item =d;
Does anyone know why?
#include <assert.h>
#include <sys/types.h>
#include <stdio.h>
struct node{
int item;
struct node *next;
};
struct node* createNode(int d){
struct node *newNode;
newNode->item = d;
//newNode->next = NULL;
return newNode;
}
int main(){
struct node *new = createNode(10);
//int x=0;
//printf("%d\n",new->item);
return 0;
}