ok this my code
Code:
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <stddef.h>
#include <stdio.h>
#include "sllist.h"
typedef struct FRUIT {
int boxes;
int crates;
}FRUIT;
int main()
{
int atest;
int result, tag;
size_t size;
SLLIST *pSllist = NULL;
char c;
FRUIT apples;
FRUIT *papples;
papples = &apples;
apples.boxes = 5;
apples.crates = 4;
printf("apples boxes = %d\n",apples.boxes);
printf("apples boxes = %d\n",papples->boxes);
/* add apples to linked list */
size = sizeof apples;
result = SLAdd(&pSllist,tag,&papples,size);
printf("result = %d\n",result);
printf("pointer value %d \n",pSllist);
atest = pSllist->((FRUIT *)Object)->boxes;
return 0;
}
The function SLAdd is taken from a book c unleashed I don't really want to post unless you really need, anyway there is some error checking in the SLAdd function and it runs ok and afterwards pSllist no longer points to null.The SLAdd function takes my fruit object and uses a void *Object to malloc then copys my fruit object using memcpy.