Beispiel #1
0
//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);
} 
Beispiel #2
0
//dua vao cay btree1
void add1()        
{
   FILE *f;
   f=fopen("nhap.txt","r");
   while(!feof(f))
   {
     p1=(dict1*)malloc(sizeof(dict1));
     fscanf(f,"%s",p1->key);
     fgets(p1->value,256,f);
     btins(bt1,p1->key,(char*)p1,sizeof(dict1)); 
     free(p1);
   }  
   fclose(f);
} 
Beispiel #3
0
int newUser(BTA* btUser, USER* users){
  int check;
 
  if(strcmp(users->userName,"")==0 || strcmp(users->passWord,"")==0){
    printf("Please input both user and pass!!\n");
    return -1;
  }
  check = btins(btUser,users->userName,(char*)users,sizeof(USER));
  if(check == 0){
    printf("You register successful\n");
    return 0;
  }
  else{
    printf("User was exsited!!Try register\n");
    return -2;
  }
}
Beispiel #4
0
void doAdd(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)  //Neu s1 khong co
    {
        btins(tree,text,btext,strlen(btext)+1);   //insert vao btree
       	strcpy(thongbao_text,"Added data !");
        gtk_label_set_text(thongbao,thongbao_text);
    }
    gtk_widget_hide(add);
    btcls(tree); 
}
Beispiel #5
0
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); 
}
Beispiel #6
0
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);
}
Beispiel #7
0
//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();
    } 
}