I am working on the same project as in this question, however with a slightly different typedef:
typedef struct {
char* word;
int index;
} data_t;
typedef struct node node_t;
typedef node {
void *data;
node_t *left;
node_t *right;
}
I am trying to split a string into individual words, sticking it into the data_t struct and then inserting it into a binary search tree. The idea is that, while looping across an input string, when it is found that the character is one which marks the end of a word, the number of characters between the start and end of the word is copied into a string, which I have attempted to do using:
strncpy(newstring, (in+wordstart), (i-wordstart));
where:
char* newstring, in;
int i, wordstart;
However, gcc gives a bus error when that particular line is called. How this bus error can be fixed and the current solution kept, or would it be wiser to look for a different solution?
The only idea I have been able to think of so far is to, one character at a time, put the characters into the string until the end of the word has been reached.