Now i have a look at your files and see the next problem.
You don't check if malloc was successfull.
You hide pointer behind typedef's. This isn't realy a problem, but it confuses many reader and if you edit this code after a long time (months or years), you will be also confused.
The name of struct linkedList is also confusing, because I don't see a linked list in your code.
It's look for me as an array of struct linkedList. But this isn't a linked list.
I have renamed this struct in my example to 'link_s' (the '_s'-suffix mean 'struct').
The name of the type is also renamed to 'link_t' (the '_t'-suffix mean 'type').
I moved the struct to the header-file.
Befor you quit, you should free all allocated memory. Therefor, i have add a function to free 'link_t'.
Example 'linkedlist.h':
Code:
#include <stdlib.h>
#include <stdio.h>
#ifndef LINKEDLIST_H
#define LINKEDLIST_H
typedef int bool;
typedef struct link_s
{
char *data;
int key;
int left;
int right;
int size;
} link_t;
link_t *createLink(int size);
bool isFull(link_t *link);
void insertFront(link_t *link, const char *newInfo);
bool isEmpty(link_t *link);
const char *removeEnd(link_t *link);
void freeLink(link_t **link);
#endif
Example 'linkedlist.c':
Code:
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include "linkedlist.h"
link_t *createLink(int size)
{
link_t *link;
if ((link = malloc(sizeof (*link))) == NULL) {
fprintf(stderr, "can't allocate link!\n");
return NULL;
}
if ((link->data = malloc(size + 1)) == NULL) {
fprintf(stderr, "can't allocate link->data!\n");
free(link);
return NULL;
}
link->size = size;
link->left = 0;
link->right = 0;
return link;
}
void freeLink(link_t **link) {
free((*link)->data);
free(*link);
*link = NULL;
}
You can test this functions with:
Code:
#include <stdio.h>
#include "linkedlist.h"
void debug_out (void *ptr) {
if (ptr)
printf("pointer: %p\n", ptr);
else
printf("pointer: (null)\n");
}
int main (void)
{
link_t *my_link = NULL;
debug_out (my_link);
my_link = createLink(int size);
debug_out (my_link);
freeLink(&my_link);
debug_out (my_link);
return 0;
}