int main(int argc, char *argv[]) { char tmpfile[80]; char key[ZKYLEN]; int status,val; BTA *dict; sprintf(tmpfile,"/tmp/bt_%d",getpid()); btinit(); if ((dict = btcrt(tmpfile,0,FALSE)) != NULL) { unlink(tmpfile); while (fgets(key,ZKYLEN,stdin) != NULL) { if (strrchr(key,'\n') != NULL) key[strlen(key)-1] = '\0'; status = binsky(dict,key,0); if (status != 0) { print_bterror(); exit(EXIT_FAILURE); } } btpos(dict,ZSTART); while (bnxtky(dict,key,&val) == 0) puts(key); } else { fprintf(stderr,"Unable to open temp btree index.\n"); } btcls(dict); return EXIT_SUCCESS; }
//khoi tao cay btree1&2 void init1() { btinit(); if (fopen(data1,"r")==NULL) bt1 = btcrt(data1,0,0); else bt1 = btopn(data1,0,0); //tra ve BTA bt2 = btcrt(data2,0,0); //tra ve BTA }
void creat_btree(BTA* btact){ IS is; dict* dic; int i; btinit(); is=new_inputstruct("dictionary.txt"); if(is==NULL){ printf("Not exsit this file\n");return ; } while((get_line(is)>=0)){ dic=(dict*)malloc(sizeof(dict)); strcpy(dic->word,is->fields[0]); for(i=1;i<is->NF;i++){ strcat(dic->mean,is->fields[i]); if(i!=is->NF-1) strcat(dic->mean," "); } btins(btact,dic->word,(char*)dic,sizeof(dict)); //printf("%s\n",dic->word); } jettison_inputstruct(is); }
int main(){ btinit(); BTA *t; FILE *fin = fopen(CSV,"r"); if(fin==NULL){ fprintf(stderr,"Cannot open file input %s:%d!!!\n",__FILE__,__LINE__); exit(1); } int size = count_line(fin); btcrt(fid,size,0); t = btopn(fid,0,0); //insert data to tree person *new_info = get_data_from_file(fin,size); add_data_to_tree(t,new_info,size); free(new_info); btcls(t); }
void creatBtreeUser(BTA* btUser){ IS is; USER* user; int i = 0; btinit(); is = new_inputstruct("user.txt"); if(is == NULL){ printf("Not exsit this file\n"); return; } while((get_line(is) >= 0)){ user = (USER*)malloc(sizeof(USER)); strcpy(user->userName,is->fields[0]); strcpy(user->passWord,is->fields[1]); user->rights = atoi(is->fields[2]); btins(btUser,user->userName,(char*)user,sizeof(USER)); if(i == 0) root = user; else i++; } jettison_inputstruct(is); }
main (int argc, char *argv[]) { printf("\nHelpful Dictionary Program\n"); btinit(); sug = btopn("data/tudienanhviet.old", 0, 0); GtkBuilder *builder; GError *error = NULL; widget = g_slice_new(Widgets); gtk_init (&argc, &argv); //init btree, mo file .dat //tree = btopn("data/tudienanhviet.dat", 0, 0); //file nay ko can mo nua //khoi tao builder va cac widget builder = gtk_builder_new (); gtk_builder_add_from_file (builder, "dict.glade", NULL); window = GTK_WIDGET (gtk_builder_get_object (builder, "window")); aboutdialog = GTK_WIDGET (gtk_builder_get_object (builder, "aboutdialog")); restore = GTK_WIDGET (gtk_builder_get_object (builder, "restore")); about = GTK_WIDGET (gtk_builder_get_object (builder, "about")); dev = GTK_WIDGET (gtk_builder_get_object (builder, "dev")); search = GTK_WIDGET (gtk_builder_get_object (builder, "search")); add = GTK_WIDGET (gtk_builder_get_object (builder, "add")); edit = GTK_WIDGET (gtk_builder_get_object (builder, "edit")); del = GTK_WIDGET (gtk_builder_get_object (builder, "del")); undo = GTK_WIDGET (gtk_builder_get_object (builder, "undo")); treeview=GTK_WIDGET (gtk_builder_get_object (builder, "treeview")); thongbao=GTK_WIDGET (gtk_builder_get_object (builder, "thongbao")); widget->searchentry = GTK_WIDGET( gtk_builder_get_object( builder, "searchentry" ) ); widget->textview = GTK_WIDGET( gtk_builder_get_object( builder, "textview" ) ); widget->foundlist = GTK_LIST_STORE( gtk_builder_get_object( builder, "foundlist" ) ); widget->suggests = GTK_WIDGET( gtk_builder_get_object( builder, "suggests" ) ); // buff=gtk_text_view_get_buffer(widget->textview); // g_signal_connect(G_OBJECT(buff) , "changed", G_CALLBACK(showUndo), (gpointer) window); //tao ket noi singal gtk_builder_connect_signals (builder, widget); g_object_unref (G_OBJECT (builder)); gtk_widget_show (window); gtk_main (); btcls(tree); btcls(sug); return 0; }