I have a header file (.h) with the following declaration.
typedef struct LinkedList LinkedList;
Afterwords in my LinkedList.c file I have the following
#include "LinkedList.h"
typedef struct Node {...} Node;
struct LinkedList {
Node *head;
int size;
} LinkedList;
This set up is similar to the one I found over here with the difference being that I did not define the data members of the struct of LinkedList in my .h file (because I want to keep the Node stuff private). My understanding of header files is that any private structs are defined at implementation (i.e. in the .c file). Is this the proper way to do this? I have a initializeList function in my LinkedList.c file where I initalize size to 0 and head to NULL.
I then compiled this into a library file using
gcc -o LinkedList -c LinkedList.c
following the directions at here.
I then have a main.c file where I have the following
#include <stdio.h>
#include <stdlib.h>
#include "LinkedList.h"
int main()
{
LinkedList list1;
initializeList(list1);
for(int index = 1; index <= 5; index++)
{
int input;
printf("Enter num: ");
scanf("%d", input);
insertNthPosition(list1, input, index);
}
for(int index = 1; index <= 5; index++)
{
printf("\n%d\n", getNthValue(list1, index));
}
return 1;
}
When I use
gcc -o main main.c
I get the following error
Storage size of 'list1' is not known