I am rather new to C and have been following a book on C algorithms. A small section has provided details on adding a node to the beginning.
For example:
Algorithm:ADD_BEG (HEAD, ITEM)
1. [Create the new node]
a) Allocate memory for NEW node.
b) IF NEW = NULL then Print: “Memory not Available” and Return
c) Set NEW→DATA = ITEM
d) Set NEW→LINK = HEAD
2. [Make the HEADER to point to the NEW node]
Set HEAD = NEW
3. Return
Here is what I have attempted:
#include <stdlib.h>
#include <stdio.h>
typedef struct node {
int DATA;
struct node * LINK;
} node_t;
node_t add_beg(struct node* head, int item){
node_t* new = NULL;
new = (node_t *)malloc(5*sizeof(node_t));
if (new == NULL){
printf("Memory not available");
return *new;
}
new ->DATA = item;
new ->LINK = head;
head = new;
return *head;
}
Output:
gcc -o exercise_1 exercise_1.c
Undefined symbols for architecture x86_64:
"_main", referenced from:
implicit entry/start for main executable
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
What does the error refer to?