Witam, jak w temacie, oto kod :
struct tr
{
char *word;
int count;
struct tr *left, *right;
};
typedef struct tr tree;
tree *add(tree *d, char *word)
{
if (!d) //d==NULL
{ //program nie sprawdza tego warunku !!
tree *new_one = (tree*)malloc(sizeof(tree)); //
new_one->word = word;
new_one->count = 1;
new_one->left = NULL;
new_one->right = NULL;
return new_one;
}
if (strcmp(d->word, word) ==0)
{
(d->count)++;
return d;
}
if (strcmp(d->word, word)<0)
{
d->left=add(d->left, word);
}
if (strcmp(d->word, word)>0)
{
d->right=add(d->right, word);
}
return d;
}
void print(tree *d)
{
if (d)
{
if (d->left)
print(d->left);
printf("%s\t %i\n", d->word, d->count);
if (d->right)
print(d->right);
}
}
int main()
{
tree nw;
nw.word = (char*)malloc(30);
nw.word = "blkaasd";
add(&nw, "lolo");
//printf("test1 \n");
// add(&nw, "ao");
//add(&nw, "bolo");
//add(&nw, "golo");
//add(&nw, "folo");
//printf("test2 ");
//print(&nw);
return 0;
}
Program nie chce sprawdzić pierwszego warunku z funkcji add. Za wszelkie podpowiedzi z góry dziękuję.