Δημοσιεύτηκε: 22 Μάιος 2013, 20:33
από ertyuiopos
καλησπερα εχω φτιαξει το ακολουθο προγραμμα

Κώδικας: Επιλογή όλων

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef struct dedomena {
char word[20];
} TStoixeioyTree;

typedef struct typos_komboy * typos_deikti;

typedef struct typos_komboy
{ TStoixeioyTree dedomena;
typos_deikti apaidi;
typos_deikti dpaidi;
} typos_komboy;

void Tree_dimiourgia(typos_deikti *tree)
{
*tree=NULL;
}
int Tree_keno(typos_deikti tree)
{
return (tree==NULL);
}
int TStree_mikrotero(TStoixeioyTree s1, TStoixeioyTree s2)
{
if( strcmp(s1.word,s2.word) >0 )
return 1;
else
return 0;
}

int TStree_megalytero( TStoixeioyTree s1, TStoixeioyTree s2)
{
if( strcmp(s1.word,s2.word) <0 )
return 1;
else
return 0;
}

void TStree_setValue (TStoixeioyTree *target,TStoixeioyTree source)
{
strcpy(target->word,source.word);
}

void Tree_eisagogi(typos_deikti *tree, TStoixeioyTree stoixeio, int *error)
{
if(Tree_keno(*tree))
{ *tree=malloc(sizeof(typos_komboy));
if(*tree==NULL)
{ *error=1;
return;
}
TStree_setValue(&((*tree)->dedomena), stoixeio);
(*tree)->apaidi=NULL;
(*tree)->dpaidi=NULL;
}
else if(TStree_mikrotero(stoixeio, (*tree)->dedomena))
Tree_eisagogi(&((*tree)->apaidi), stoixeio, error);
else if(TStree_megalytero(stoixeio, (*tree)->dedomena))
Tree_eisagogi(&((*tree)->dpaidi), stoixeio, error);
else
*error=1;
}

int search(typos_komboy *tree,char *word)
{
if (tree==NULL)
return 0;

if (!strcmp(tree->dedomena.word,word))
return 1;

if (strcmp(tree->dedomena.word,word)>0) return search(tree->apaidi,word);
return search(tree->dpaidi,word);
}

int main(void){

typos_deikti tree;

Tree_dimiourgia(&tree);

TStoixeioyTree s;

char t[256];

FILE *file1,*f2;

int i=0,error=0,r=0,j=0,k=0;

if ((file1=fopen("file1.txt","r"))==NULL)
{
printf("Unable to open file1.txt\n");
getchar();
return 1;
}

if((f2=fopen("file2.txt","r"))==NULL)
{
printf("Unable to open data2.txt\n");
getchar();
return 0;
}

while (fscanf(file1,"%s",s)!=EOF)
{
Tree_eisagogi(&tree,s,&error);
i++;
}

while(fscanf(f2,"%s",t)!=EOF)
{
if(search(tree,t))
{
r++;
printf("%s found\n",t);
}
else
{
j++;
printf("%s not found\n",t);
}
k++;
}

printf("%d items was stored in tree\n",i);

printf("%d found %d not found %d searched\n",r,j,k);

getchar();
return 0;
}


το προβλημα ειναι οτι για καποιο λογο δεν μου αποθηκευεται τιποτα στο tree πιστευω οτι καλο λαθος την Tree_eisagogi(&tree,s,&error);..οποια βοηθεια εχετε ευπροσδεκτη! ευχαριστω εκ των προτερων

Υ.Γ:Μην αναρωτιεστε για τα structs ετσι ειναι απο την ασκηση δεν μπορω να τα αλλαξω