}; /* The structure works like this: Create a structure of a node, * allocate memory for the node to be put into memory, put and * point previous node to new node. Point new node to NULL and * add integer value as needed * * root node:1 node:2 root * [*pointer]----->[(value)|*pointer]----->[(value)|*pointer]----->[NULL] * * It should be noted that *pointer points to the address holding the data * structure and does NOT point to the (value) address nor does it * point to the value of node:#. */ struct NODE *insert(struct NODE *list, int n); struct NODE *prints(struct NODE *list); int main(){ //declare the root node and traversal node struct NODE *initial = NULL; /* Root node. Notice it points to NULL; is currently * an empty list of nodes. */ //control variables for terminal int input, value; //terminal to control linked list program for(;;){ switch(input){ initial = insert(initial, value); break; case 2: prints(initial); break; default: return(0); }; }; }//end main /* Start function definitions */ //insert: insert a new node into linked list // struct NODE *list: passes the root of the linked list struct NODE *insert(struct NODE *list, int n){ //create and allocate new node struct NODE *new; /* New node */ }; //begin adding values to new node new->value = n; /* Input value into data structure new NODE*/ new->link = list; /* new will point to list argument passed */ return(new); /* return new node to list */ }//end *insert //prints: prints the values for each node in the linked list struct NODE *prints(struct NODE *list){ for(;list != NULL; list = list->link){ } }//end *prints
Standard input is empty
prog.c:1:1: error: expected identifier or '(' before '}' token
};
^
prog.c: In function 'main':
prog.c:22:25: error: 'NULL' undeclared (first use in this function)
struct NODE *initial = NULL; /* Root node. Notice it points to NULL; is currently
^
prog.c:22:25: note: each undeclared identifier is reported only once for each function it appears in
prog.c:30:3: warning: implicit declaration of function 'printf' [-Wimplicit-function-declaration]
printf("Linked List\nCommands:\n1: Add node\n2: View list\n\n");
^
prog.c:30:3: warning: incompatible implicit declaration of built-in function 'printf'
prog.c:30:3: note: include '<stdio.h>' or provide a declaration of 'printf'
prog.c:31:3: warning: implicit declaration of function 'scanf' [-Wimplicit-function-declaration]
scanf("%d", &input); /* command input to control while loop and switch statement */
^
prog.c:31:3: warning: incompatible implicit declaration of built-in function 'scanf'
prog.c:31:3: note: include '<stdio.h>' or provide a declaration of 'scanf'
prog.c: In function 'insert':
prog.c:58:12: warning: implicit declaration of function 'malloc' [-Wimplicit-function-declaration]
if((new = malloc(sizeof(struct NODE))) == NULL){ /* Allocate space for new struture */
^
prog.c:58:12: warning: incompatible implicit declaration of built-in function 'malloc'
prog.c:58:12: note: include '<stdlib.h>' or provide a declaration of 'malloc'
prog.c:58:26: error: invalid application of 'sizeof' to incomplete type 'struct NODE'
if((new = malloc(sizeof(struct NODE))) == NULL){ /* Allocate space for new struture */
^
prog.c:58:44: error: 'NULL' undeclared (first use in this function)
if((new = malloc(sizeof(struct NODE))) == NULL){ /* Allocate space for new struture */
^
prog.c:59:3: warning: incompatible implicit declaration of built-in function 'printf'
printf("Allocation Error: malloc returned the NULL pointer. Terminating.\n");
^
prog.c:59:3: note: include '<stdio.h>' or provide a declaration of 'printf'
prog.c:60:3: warning: implicit declaration of function 'exit' [-Wimplicit-function-declaration]
exit(EXIT_FAILURE);
^
prog.c:60:3: warning: incompatible implicit declaration of built-in function 'exit'
prog.c:60:3: note: include '<stdlib.h>' or provide a declaration of 'exit'
prog.c:60:8: error: 'EXIT_FAILURE' undeclared (first use in this function)
exit(EXIT_FAILURE);
^
prog.c:64:5: error: dereferencing pointer to incomplete type 'struct NODE'
new->value = n; /* Input value into data structure new NODE*/
^
prog.c: In function 'prints':
prog.c:74:15: error: 'NULL' undeclared (first use in this function)
for(;list != NULL; list = list->link){
^
prog.c:75:3: warning: incompatible implicit declaration of built-in function 'printf'
printf("%d ", list->value); /* derencerences node pointer and accesses value */
^
prog.c:75:3: note: include '<stdio.h>' or provide a declaration of 'printf'
prog.c:78:2: warning: incompatible implicit declaration of built-in function 'printf'
printf("\n");
^
prog.c:78:2: note: include '<stdio.h>' or provide a declaration of 'printf'
prog.c:80:1: warning: control reaches end of non-void function [-Wreturn-type]
}//end *prints
^
Standard output is empty