I have function along the lines of:
void insert(btnode **ptr, char *name, unsigned int race, unsigned int class, unsigned int id, char *guild)
{
if((*ptr) == NULL)
{
(*ptr) = (btnode*)malloc(sizeof(btnode));
(*ptr)->rec = (record*)malloc(sizeof(record));
(*ptr)->left=NULL;
(*ptr)->right=NULL;
strcpy((*ptr)->rec->name,name);
(*ptr)->rec->race = race;
(*ptr)->rec->class = class;
(*ptr)->rec->id = id;
strcpy((*ptr)->rec->guild, guild);
}
else
{
if((*ptr)->rec->id > id)
{
insert(&((*ptr)->left),name,race,class,id,guild);
}
else
{
insert(&((*ptr)->right),name,race,class,id,guild);
}
}
}
It is use to insert values into a binary tree
The issue I'm having is when the first node is null everything works fine. But when the function has to call its self the char array doesn't print what its meant to.
Any suggestions how to solve this issue?
EDIT: full code added, there is no problems with unsnigned ints only chars.
struct decelerations:
#define TWOBYTEINT 16
#define FOURBYTEINT 32
#define MAXIMUMLINE 70
#define FALSE 0
#define TRUE 1
typedef struct record
{
char name[13];
unsigned int race : TWOBYTEINT;
unsigned int class : TWOBYTEINT;
unsigned int id : FOURBYTEINT;
char guild[30];
}__attribute__((packed)) record;
typedef struct node
{
record * rec;
struct node *right, *left;
}btnode;
if (null)is alwaysfalseand will never execute the body. I guess you meant something along the lines ofif (!node)... ? Additionally you should show more of your code, what isinsert?nullwould be some check to see whether a matching node exists)