Linked list - why this bit of code?
Below is the first bit of a linked list program that I am trying to learn about. Can someone please tell me why the 4 lines in bold are required? I am confused as they seem to be just the name of functions that occur later in the program, however when I write programs I have never declared a function in this way before. Why would it be correct to write those 4 lines, in addition to the actual functions later on?
Thankyou,
Chris
Code:
#include <stdio.h>
#include <stdlib.h>
/* node type for linked list */
struct node {
int val;
struct node *next;
};
/* will point to beginning of list */
struct node *list = NULL;
void print_list(void);
void add_item(char flag);
void delete_item(void);
void delete_list(void);
int main(void) {
char choice;
char line[50];
printf("Linked list demonstration (integers)\n");
while (choice != 'q')
{
printf("(1) Print contents of list\n");
printf("(2) Add item to beginning of list\n");
printf("(3) Add item to end of list\n");
printf("(4) Delete item from list\n");
printf("(5) Delete entire list\n");
printf("(q) Quit\n");
printf("Select an option: ");
fgets(line, sizeof(line), stdin);
sscanf(line, "%c", &choice);
switch (choice)
{
case '1' :
print_list();
break;
case '2' :
add_item('b'); /* add to beginning */
break;
case '3' :
add_item('e'); /* add to end */
break;
case '4' :
delete_item();
break;
case '5' :
delete_list();
break;
case 'q' :
printf("Cleaning up...\n");
delete_list(); /* unnecessary, but good habit */
break;
default :
printf("Error - invalid input\n");
break;
}
}
return 0;
}
void print_list(void)
{
if.............