The point of this assignment was to get used to working with multiple files in C (part of a linked-list). The files are separate and only work when compiled together. Here they are:
Code:
#include "prog10.h"
//main.c
int main (void)
{
PERSON *head = NULL;
head = createList();
print_list(head);
release_memory(head);
printf("Done\n");
return 0;
}
Code:
PERSON* createList(void)
{//createList.c
char answer;
PERSON *current, *pervious, *head=NULL;
while(1)
{
printf("Add a person to the List?[y/n]\n");
scanf("%c", &answer);
if(answer=='n')
return head;
current = (PERSON *)malloc(sizeof(PERSON) );
printf("Enter a name:");
scanf("%s", current->name);
printf("Enter persons age:");
scanf("%i", ¤t->age);
while(getchar() != '\n');
if(head==NULL)
head=current;
else
previous->next_ptr=current;
current->next_ptr=NULL;
previous=current;
}
}
Code:
void print_list(PERSON *person_ptr)
{
//p10.c
while(person_ptr != NULL)
{
printf("Name: %s", person_ptr->name);
printf("Age: %i", &person_ptr->age);
person_ptr=person_ptr->next_ptr;
}
}
Code:
#include "prog10.h"
void release_memory(PERSON *person_ptr)
{//releaseMemory.c
PERSON *tmp_next_ptr;
while (person_ptr != NULL)
{
tmp_next_ptr = person_ptr->next_ptr;
free(person_ptr);
person_ptr = tmp_next_ptr;
}
puts("Memory Released");
}
Every time I compile the program, I get an error in the first line of p10.c. It says that there is an error before ' * ' in function print_list. The next error says that NULL has not been declared. Can anyone help?