//dua du lieu vao cay btree2 void add2() { FILE *f; f=fopen("nhap.txt","r"); int kt,i,j; while(!feof(f)) { p2=(dict2*)malloc(sizeof(dict2)); p1=(dict1*)malloc(sizeof(dict1)); fscanf(f,"%s",p1->key); fgets(p1->value,256,f); p2->i=0; soundex(sound,p1->key,1,1); if(btsel(bt2,sound,(char*)p2,sizeof(dict2),&rsize2)!=0) { strcpy(p2->key[p2->i],p1->key); strcpy(p2->value[p2->i],p1->value); btins(bt2,sound,(char*)p2,sizeof(dict2)); } else { p2->i++; strcpy(p2->key[p2->i],p1->key); strcpy(p2->value[p2->i],p1->value); if(strcmp(p2->key[p2->i],p2->key[p2->i-1])!=0) btupd(bt2,sound,(char*)p2,sizeof(dict2)); } free(p2); free(p1); } fclose(f); }
void doEdit(GtkWidget *button, Widgets *app){ tree = btopn("data/tudienanhviet.dat", 0, 0); GtkTextIter start, end; gchar *text,*btext; GtkTextBuffer *textbuffer; textbuffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(app->textview)); text = gtk_entry_get_text(GTK_ENTRY(app->searchentry)); gtk_text_buffer_get_bounds (textbuffer, &start, &end); btext=gtk_text_buffer_get_text(textbuffer,&start,&end ,FALSE); long value; if (bfndky(tree,text,&value)==0) { btupd(tree,text,btext,strlen(btext)+1); strcpy(thongbao_text,"Edited data !"); gtk_label_set_text(thongbao,thongbao_text); } gtk_widget_hide(add); btcls(tree); }
//thay doi thong tin tren key void edit() { char xau[20]; p1=(dict1*)malloc(sizeof(dict1)); printf("\nNhap tu muon them:"); scanf("%*c");gets(xau); strcpy(p1->key,xau); if (btsel(bt1,p1->key,(char*)p1,sizeof(dict1),&rsize1)!=0) { mygetch(); printf("\nNhap y nghia:");gets(p1->value); btins(bt1,p1->key,(char*)p1,sizeof(dict1)); printf("\nDa cap nhat"); mygetch(); } else { mygetch(); printf("\nNhap vao nghia tu:");gets(p1->value); btupd(bt1,p1->key,(char*)p1,sizeof(dict1)); printf("\nNghia da duoc thay doi"); mygetch(); } }