版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)
文檔簡介
基于GTK的拼音輸入法/i_love_lei_lei/blog/category/%C7%B6%C8%EB%CA%BD基于GTK的拼音輸入法(1)2009-11-1710:03#include<gtk/gtk.h>
#include<stdio.h>
#include<string.h>#include<ctype.h>
#include<stdlib.h>charT[]={"abcdefghijklmnopqrstuvwxyz"};
charTT[]={"ABCDEFGHIJKLMNOPQRSTUVWXYZ"};charpin_y[20];
charpy_store[10];
char*CH_CON[10][9];
charOPERATE;
//操作標志位;
intSYMBOL=0;
//測試字數(shù)組的標志位,用來判斷循環(huán)的
intROW,COLUMN,ROW_MAX,COLUMN_MIN;
//抽出字的數(shù)組的行列值
charci_buffer[20];
//預(yù)選存放字詞的~
charci_py_buffer[20];
//存放詞的拼音;charhanzi[60];
//label顯示用的變量
charlabel_swap[30];
charentry_buffer[100];
GtkWidget*entry_all;
GtkWidget*label_py,*label_cn,*label_yx;structchinese_container
{
charlabel[2];
charpy[8];
charch[3];
}s;structChinese_data
{
chardata[4];
//存放的一個字
intFrequency;
//使用的頻度
structChinese_data*next;
//指向下一個字
//structChinese_data*pre;//指向前一個字
};structword
{
chardata[20];
intFrequency;
structword*next;
};structElement
{charElementType;//元素的類型
structChinese_data*ch;//存放數(shù)據(jù)(漢子)
structElement*Father;//父指針
intOld_new;//是新的還是舊的詞
intIsword;//判斷是字還是詞
structElement*letter[26];//孩子指針
structword*ci;
//詞的指針
};structElement*pointer=NULL;
structElement*p_element=NULL;
structElement*father=NULL;
structChinese_data*pointer_ch=NULL;
structChinese_data*pu=NULL;
structword*pointer_ci,*pi;/*******************************************************************
函數(shù)名:creat_node_data;
輸入?yún)?shù):void;
輸出:void;
功能:開辟漢字的存儲空間;
********************************************************************/
structChinese_data*creat_node_data(void)
{
structChinese_data*c;
c=(structChinese_data*)malloc(sizeof(structChinese_data));
returnc;
}/*******************************************************************
函數(shù)名:creat_node_word;
輸入?yún)?shù):void;
輸出:void;
功能:開辟詞的存儲空間,
********************************************************************/
structword*creat_node_word(void)
{
structword*c;
c=(structword*)malloc(sizeof(structword));
returnc;
}/*******************************************************************
函數(shù)名:creat_node;
輸入?yún)?shù):void;
輸出:void;
功能:開辟鏈表的存儲空間,
********************************************************************/
structElement*creat_node(void)
{
structElement*b;
b=(structElement*)malloc(sizeof(structElement));
returnb;
}/*******************************************************************
函數(shù)名:bl;
輸入?yún)?shù):structElement*head;
輸出:void;
功能:對輸入的鏈表進行遍歷輸出,按照漢子表的形式輸出,
********************************************************************/
voidbl(structElement*head)
//等深度遍歷函數(shù)
{
inti,j,k;
structChinese_data*ph;
structElement*pe;
structword*pi;
charpiny[8],piy[8];
charci_piny[20],ci_piy[20];
piny[0]='\0';
piy[0]='\0';
for(i=0;i<26;i++)
{
if(head->letter[i])
{
head=head->letter[i];
if(head->ch!=NULL)
//可以在底下一級插入排序函數(shù)即為遍歷排序或者插入釋放類存的語句!
{
ph=head->ch;
pe=head;
j=0;
while(pe->ElementType)
//得到的倒序拼音
{
sprintf(&piny[j],"%c",pe->ElementType);
pe=pe->Father;
j++;
}
for(k=0;k<j;k++)
//再倒序排列
{
//
piy[k]=piny[j-k-1];
//
}
//
while(j<8)
//
{
//
piy[j]='\40';
//這部分取得拼音,且補上空格!
j++;
//
}
//
piy[j]='\0';
//
for(k=0;k<26;k++)
{
if(piy[0]==T[k])
{
printf("%c",TT[k]);//打印出大寫字母標志
}
}
printf("%s",piy);
//打印出拼音
pe=NULL;
ph=head->ch;
while(ph!=NULL)
{
printf("%s",ph->data);
//打印拼音之后的字
ph=ph->next;
}
printf("\n");
//打印換行符號,即拼音后面的漢子結(jié)束了。
ph=NULL;
//清空指針
}
if(head->ci!=NULL)
{
pe=head;
j=0;
while(pe->ElementType)
//得到的倒序拼音
{
sprintf(&ci_piny[j],"%c",pe->ElementType);
pe=pe->Father;
j++;
}
for(k=0;k<j;k++)
//再倒序排列
{
ci_piy[k]=ci_piny[j-k-1];
}
ci_piy[j]='\0';
//printf("%s\n",ci_piy);
for(k=0;k<26;k++)
{
if(ci_piy[0]==T[k])
{
printf("%c",TT[k]);//打印出大寫字母標志
printf("%c",T[2]);
}
}
printf("%s",ci_piy);
pe=NULL;
pi=head->ci;
while(pi!=NULL)
{
printf("%s",pi->data);
pi=pi->next;
}
printf("\n");
pi=NULL;
}
bl(head);
head=head->Father;
}
}
}/*******************************************************************
函數(shù)名:order;
輸入?yún)?shù):structElement*Head;
輸出:void;
功能:對輸入的鏈表結(jié)構(gòu)里面有詞的節(jié)點按照使用頻度值進行排序,排序完畢后,將排序完的
表頭賦值給輸入的指針;
********************************************************************/
voidorder(structElement*Head)/*排序函數(shù)*/
{
structwordsh;
structword*head;
sh.next=Head->ci;
head=&sh;
structword*temp=NULL;//默認為NULL,也就是鏈表的結(jié)尾
structword*ptr1=head;
structword*ptr2=head->next;while(ptr1->next!=temp)//(ptr1!=NULL)
{
while(ptr2->next!=temp)//(ptr2!=NULL)
{
if(ptr1->next->Frequency<ptr2->next->Frequency)//(ptr1->score>ptr2->score)
{//交換ptr1->link和ptr2->link
ptr1->next=ptr2->next;
ptr2->next=ptr2->next->next;//temp->link=ptr2;
ptr1->next->next=ptr2;//ptr2->link=ptr1;
}
ptr1=ptr1->next;//ptr2=ptr2->link;
ptr2=ptr1->next;//從上面移動下來的
}
temp=ptr2;//新加的
ptr1=head;//ptr1=ptr1->link;
ptr2=ptr1->next;//從上面移動下來的
}
head=head->next;
Head->ci=head;
}/*******************************************************************
函數(shù)名:sort;
輸入?yún)?shù):structElement*Head;
輸出:void;
功能:對輸入的鏈表結(jié)構(gòu)里面有字的節(jié)點按照使用頻度值進行排序,排序完畢后,將排序完的
表頭賦值給輸入的指針;
********************************************************************/
voidsort(structElement*Head)/*排序函數(shù)*/
{structChinese_datash;
structChinese_data*head;
sh.next=Head->ch;
head=&sh;
structChinese_data*temp=NULL;//默認為NULL,也就是鏈表的結(jié)尾
structChinese_data*ptr1=head;
structChinese_data*ptr2=head->next;while(ptr1->next!=temp)//(ptr1!=NULL)
{
while(ptr2->next!=temp)//(ptr2!=NULL)
{
if(ptr1->next->Frequency<ptr2->next->Frequency)//(ptr1->score>ptr2->score)
{//交換ptr1->link和ptr2->link
ptr1->next=ptr2->next;
ptr2->next=ptr2->next->next;//temp->link=ptr2;
ptr1->next->next=ptr2;//ptr2->link=ptr1;
}
ptr1=ptr1->next;//ptr2=ptr2->link;
ptr2=ptr1->next;//從上面移動下來的
}
temp=ptr2;//新加的
ptr1=head;//ptr1=ptr1->link;
ptr2=ptr1->next;//從上面移動下來的
}
head=head->next;
Head->ch=head;
}/*******************************************************************
函數(shù)名:blpx;
輸入?yún)?shù):structElement*Head;
輸出:void;
功能:用字,詞的排序函數(shù)來實現(xiàn)整個鏈表的頻度排序;
********************************************************************/
voidblpx(structElement*head)
//遍歷排序總體的
{
inti,j,k;
structChinese_data*p_ch;
//structElement*pe;
for(i=0;i<26;i++)
{
if(head->letter[i])
{
head=head->letter[i];
//blpx(head);
if(head->ch!=NULL)
{
sort(head);
//對這一級的漢子排序
}
if(head->Isword)
{
order(head);
}
blpx(head);
head=head->Father;
}
}
}/*******************************************************************
函數(shù)名:blw;
輸入?yún)?shù):structElement*Head;
輸出:void;
功能:對輸入的鏈表進行回寫,將鏈表節(jié)點的字,詞寫入文件中;
********************************************************************/
voidblw(structElement*head)
//等深度遍歷函數(shù)
{
FILE*w_file;
inti,j,k;
structChinese_data*ph;
structword*pi;
structElement*pe;
charpiny[8],piy[8];
charc_piny[20],c_piy[20];
char*space="";
char*enter="\n";
piny[0]='\0';
piy[0]='\0';
for(i=0;i<26;i++)
{
if(head->letter[i])
{
head=head->letter[i];
//blw(head);
if(head->ch!=NULL)
//可以在底下一級插入排序函數(shù)即為遍歷排序或者插入釋放類存的語句!
{
ph=head->ch;
pe=head;
j=0;
while(pe->ElementType)
//得到的倒序拼音
{
//strncpy(&piny[j],&(pe->ElementType),1);
sprintf(&piny[j],"%c",pe->ElementType);
pe=pe->Father;
j++;
}
for(k=0;k<j;k++)
//再倒序排列
{
//
piy[k]=piny[j-k-1];
//
}
//
while(j<8)
//
{
//
piy[j]='\40';
//這部分取得拼音,且補上空格!
j++;
//
}
//
piy[j]='\0';
//
for(k=0;k<26;k++)
{
if(piy[0]==T[k])
{
//printf("%c",TT[k]);
//大寫字母
w_file=fopen("dx","a+b");
fwrite(&TT[k],sizeof(char),1,w_file);
//寫大寫字母標記位置!
fwrite(space,sizeof(char),1,w_file);
//大寫字母+空格
fclose(w_file);
}
}
//printf("%s",piy);
//打印出拼音
pe=NULL;
ph=head->ch;
w_file=fopen("dx","a+b");
//
fwrite(piy,sizeof(char),8,w_file);
//寫入拼音
fclose(w_file);
//
while(ph)
{
//printf("%s",ph->data);
//拼音之后的字
w_file=fopen("dx","a+b");
fwrite(ph->data,sizeof(char),3,w_file);
fclose(w_file);
ph=ph->next;
}
//printf("\n");
ph=NULL;
w_file=fopen("dx","a+b");
fwrite(enter,sizeof(char),strlen(enter),w_file);
//寫換行
fclose(w_file);
}
if(head->ci!=NULL)
{
pi=head->ci;
pe=head;
j=0;
while(pe->ElementType)
//得到的倒序拼音
{
//strncpy(&piny[j],&(pe->ElementType),1);
sprintf(&c_piny[j],"%c",pe->ElementType);
pe=pe->Father;
j++;
}
for(k=0;k<j;k++)
//再倒序排列
{
//
c_piy[k]=c_piny[j-k-1];
//
}
/*
//
while(j<20)
//
{
//
c_piy[j]='\40';
//這部分取得拼音,且補上空格!
j++;
//
}*/
//
c_piy[j]='\0';
//
for(k=0;k<26;k++)
{
if(c_piy[0]==T[k])
{
//printf("%c",TT[k]);
//大寫字母
w_file=fopen("dx","a+b");
fwrite(&TT[k],sizeof(char),1,w_file);
//寫大寫字母標記位置!
fwrite(&T[2],sizeof(char),1,w_file);
//寫詞標記位"c"
fclose(w_file);
}
}
//printf("%s",piy);
//打印出拼音
pe=NULL;
pi=head->ci;
w_file=fopen("dx","a+b");
//
fwrite(c_piy,sizeof(char),j,w_file);
//寫入詞的拼音
fclose(w_file);
//
while(pi)
{
//printf("%s",ph->data);
//拼音之后的字
w_file=fopen("dx","a+b");
fwrite(pi->data,sizeof(char),strlen(pi->data),w_file);
//詞的長度不定~
fwrite(&T[2],sizeof(char),1,w_file);
fclose(w_file);
pi=pi->next;
}
//printf("\n");
pi=NULL;
w_file=fopen("dx","a+b");
fwrite(enter,sizeof(char),strlen(enter),w_file);
//寫換行
fclose(w_file);
}
blw(head);
head=head->Father;
}
}
}/*******************************************************************
函數(shù)名:read_file;
輸入?yún)?shù):void;
輸出:void;
功能:讀取漢子碼表的漢子,生成檢索用的鏈表;
********************************************************************/
voidread_file(void)
{
FILE*p;
charpos;
charci_pos;
charpp[20];
inti,j,k,x;
p=fopen("dx","r");
father=(structElement*)malloc(sizeof(structElement));
//開辟結(jié)構(gòu)體空間
pointer=father;
while(!feof(p))
{
fread(&pos,1,1,p);
//讀取一行的首字母標號(大寫的)
if(isupper(pos))
//判斷是否是大寫字母
{
fread(&ci_pos,1,1,p);
//printf("%c\n",ci_pos);
if(ci_pos=='c')
{
fread(&ci_pos,1,1,p);
i=1;
while(islower(ci_pos))
{
fread(&ci_pos,1,1,p);
i++;
}
//printf("詞拼音長度為:%d\n",i-1);
fseek(p,-i,SEEK_CUR);
memset(pp,0,20);
fread(pp,i-1,1,p);
//printf("詞的拼音為:%s\n",pp);
j=0;
for(i=0;i<20;i++)
{
if(islower(pp[i]))j++;
//判斷詞拼音字長(位數(shù))
}
//printf("測試得到的詞長:%d\n",j);
for(x=0;x<=j;x++)
//固定指針的位置:
{
p_element=pointer;
for(k=0;k<26;k++)
//即根據(jù)拼音的長度把指針指向?qū)?yīng)的節(jié)點
{
if(pp[x]==T[k])
//判斷是那一個字母的指針
{
if(pointer->letter[k]==NULL)
{
//printf("%d\n",k);
pointer->letter[k]=creat_node();
pointer=pointer->letter[k];
pointer->ElementType=pp[x];
pointer->ch=NULL;
pointer->ci=NULL;
for(i=0;i<26;i++)
{
pointer->letter[i]=NULL;
}
pointer->Father=p_element;
}
else
{
pointer=pointer->letter[k];
}
}
}
}
memset(pp,0,20);
pointer->Isword=1;
pointer->ci=creat_node_word();
//開辟詞存儲空間
pointer_ci=pointer->ci;
while(fread(&ci_pos,1,1,p)&&(ci_pos!='\n'))//行讀取的判斷
{
i=0;
while(ci_pos!='c')
{
fread(&ci_pos,1,1,p);
i++;
}
fseek(p,-1,SEEK_CUR);
fseek(p,-i,SEEK_CUR);
fread(pp,i,1,p);
pp[i]='\0';
sprintf(pointer_ci->data,"%s",pp);
//填充對應(yīng)表頭的漢字存儲空間
//
printf("詞:%s\n",pointer_ci->data);
pi=pointer_ci;
pointer_ci->next=creat_node_word();
//指向下一個
pointer_ci=pointer_ci->next;
memset(pp,0,20);
fseek(p,1,SEEK_CUR);
}
free(pi->next);
//是否釋放了內(nèi)存空間????
pi->next=NULL;//收尾
pointer=father;
}
elseif(ci_pos=='')
{
//fseek(p,-2,SEEK_CUR);
//fread(s.label,1,2,p);
fread(s.py,1,8,p);
//讀取標號,即拼音“a“
j=0;
for(i=0;i<8;i++)
{
if(islower(s.py[i]))j++;
//判斷拼音字長(位數(shù))
}
for(x=0;x<j;x++)
//固定指針的位置:
{
p_element=pointer;
for(k=0;k<26;k++)
//即根據(jù)拼音的長度把指針指向?qū)?yīng)的節(jié)點
{
if(s.py[x]==T[k])
//判斷是那一個字母的指針
{
if(pointer->letter[k]==NULL)
{
//printf("%d\n",k);
pointer->letter[k]=creat_node();
pointer=pointer->letter[k];
pointer->ElementType=s.py[x];
pointer->Father=p_element;
}
else
{
pointer=pointer->letter[k];
}
}
}
}
pointer->ch=creat_node_data();
//開辟漢子存儲空間
pointer_ch=pointer->ch;
while(fread(&pos,1,1,p)&&(pos!='\n'))//行讀取的判斷
{
fseek(p,-1,SEEK_CUR);
fread(s.ch,1,3,p);
//printf("%s",s.ch);
sprintf(pointer_ch->data,"%s",s.ch);
//填充對應(yīng)表頭的漢字存儲空間
pu=pointer_ch;
pointer_ch->next=creat_node_data();
//指向下一個
pointer_ch=pointer_ch->next;
s.ch[0]='\0';
}
free(pu->next);
//是否釋放了內(nèi)存空間????
pu->next=NULL;//收尾
//printf("%s","yihangjiesu");
pointer=father;
}
}
}
fclose(p);
}/*******************************************************************
函數(shù)名:write_file;
輸入?yún)?shù):structElement*Head;
輸出:void;
功能:將原始的文件清空,寫入新的鏈表節(jié)點的字詞;
********************************************************************/
voidwrite_file(structElement*head)
{
FILE*p;
p=fopen("dx","w");
fclose(p);
blw(head);
}/*******************************************************************
函數(shù)名:s_free;
輸入?yún)?shù):structElement*Head;
輸出:void;
功能:釋放鏈表的內(nèi)存空間;
********************************************************************/
voids_free(structElement*head)
//釋放內(nèi)存~
{
inti,j,k;
structChinese_data*p_ch,*p_ch_free;
structElement*p_element_free;
charpiny[10],piy[10];
for(i=0;i<26;i++)
{
if(head->letter[i])
{
head=head->letter[i];
s_free(head);
if(head->ch!=NULL)
//可以在底下一級插入排序函數(shù)即為遍歷排序或者插入釋放類存的語句!
{
p_ch=head->ch;
head->ch=NULL;
while(p_ch!=NULL)
{
p_ch_free=p_ch;
p_ch=p_ch->next;
free(p_ch_free);
}
p_ch=NULL;
}
p_element_free=head;
head=head->Father;
free(p_element_free);
p_element_free=NULL;
}
}
}/*******************************************************************
函數(shù)名:chose;
輸入?yún)?shù):char*p1,char*p2;
輸出:void;
功能:輸入操作,選擇選中的詞;
********************************************************************/
voidchose(char*p1,char*p2)
//選擇后對應(yīng)的操作
{
//printf("開始調(diào)用CHOSE函數(shù)!\n");
structElement*p_e;
structChinese_data*p_ch;
structword*p_ci;
intfind_flag;
inti,j,k;
p_e=father;
find_flag=0;
i=0;
while(p1[i])
//查找到字的存儲區(qū)域
{
for(j=0;j<26;j++)
{
if(p1[i]==T[j])
{
p_e=p_e->letter[j];
}
}
i++;
}
if(p_e->Isword)
{
p_ci=p_e->ci;
while(p_ci)
{
if(!strcmp(p_ci->data,p2))//查早到對應(yīng)的字
{
p_ci->Frequency++;
find_flag=1;
break;
}
if(p_ci->next!=NULL)
{
p_ci=p_ci->next;
}
else
{
break;
}
}
}
if(p_e->ch!=NULL)
{
p_ch=p_e->ch;
}
//-----------------------------------------------------------------//
elseif(p_e->ch==NULL)
{
//printf("%s\n",p_e->ch->data);
k=0;
while(k<26)
{
if((p_e->letter[k]!=NULL)&&(p_e->letter[k]->ch!=NULL))
{
p_ch=p_e->letter[k]->ch;
//printf("%s\n",p_ch->data);打印處于選擇的字;
break;
}
k++;
}
}
//--------------------------------------------------------------------------//
//k=strlen(p2);
//調(diào)試用
//printf("%s\n",p2);
//printf("%d\n",k);
if(!find_flag)
{
while(p_ch)
{
if(!strncmp(p_ch->data,p2,3))//查早到對應(yīng)的字
{
p_ch->Frequency++;
break;
}
p_ch=p_ch->next;
}
find_flag=0;
strcat(ci_buffer,p_ch->data);
//預(yù)選字詞;
ci_buffer[strlen(ci_buffer)]='\0';
strcat(ci_py_buffer,p1);
ci_py_buffer[strlen(ci_py_buffer)]='\0';
}
else
{
strcat(ci_buffer,p_ci->data);
ci_buffer[strlen(ci_buffer)]='\0';
strcat(ci_py_buffer,p1);
ci_py_buffer[strlen(ci_py_buffer)]='\0';
find_flag=0;
}
}
查看文章
基于GTK的拼音輸入法(2)2009-11-1710:03/*******************************************************************
函數(shù)名:creat_word;
輸入?yún)?shù):structElement*head,char*ci_buffer,char*ci_py_buffer;
輸出:structElement*p;
功能:造詞;
********************************************************************/
structElement*creat_word(structElement*head,char*ci_buffer,char*ci_py_buffer)
//參數(shù)為:1字詞拼音,2字詞;
{
inti,j,k,n,x;
intbz;
intci_cmp_flag;
structword*p_ci;
structElement*pointer,*p_element;
chartest[20];
ci_cmp_flag=1;
pointer=head;
//引用的全局變量
i=strlen(ci_py_buffer);
j=strlen(ci_buffer);
if(j>3)
{
for(x=0;x<i;x++)
//固定指針的位置:
{
p_element=pointer;
for(k=0;k<26;k++)
//即根據(jù)拼音的長度把指針指向?qū)?yīng)的節(jié)點
{
if(ci_py_buffer[x]==T[k])
//判斷是那一個字母的指針
{
if(pointer->letter[k]==NULL)
{
pointer->letter[k]=creat_node();
pointer=pointer->letter[k];
pointer->ElementType=T[k];
pointer->ch=NULL;
pointer->ci=NULL;
for(bz=0;bz<26;bz++)
{
pointer->letter[bz]=NULL;
}
pointer->Father=p_element;
}
elseif(pointer->letter[k]!=NULL)
{
pointer=pointer->letter[k];
}
}
}
}
if(pointer->ci!=NULL)
//缺少比較是否相同的詞語!
{
p_ci=pointer->ci;
ci_cmp_flag=strcmp(p_ci->data,ci_buffer);
while((p_ci->next!=NULL)&&ci_cmp_flag)
{
p_ci=p_ci->next;
ci_cmp_flag=strcmp(p_ci->data,ci_buffer);
if(!ci_cmp_flag)break;
}
if(ci_cmp_flag)
{
p_ci->next=creat_node_word();
p_ci->next->next=NULL;
sprintf(p_ci->next->data,"%s",ci_buffer);
}
}
else
{
pointer->Isword=1;
pointer->ci=creat_node_word();
p_ci=pointer->ci;
p_ci->next=NULL;
sprintf(p_ci->data,"%s",ci_buffer);
}
}
pointer=father;
//printf("%s\n",ci_buffer);
//printf("%s\n",ci_py_buffer);
memset(ci_buffer,0,20);
memset(ci_py_buffer,0,20);
returnpointer;
}/*******************************************************************
函數(shù)名:test_py;
輸入?yún)?shù):char*p;
輸出:void;
功能:檢測輸入的拼音,并抽出對應(yīng)拼音的漢子,以便選擇操作;
********************************************************************/
voidtest_py(char*p)
{
structElement*p_e;
structChinese_data*p_ch;
structword*p_ci;
inti,j,k,BZW;
intpy_longth;
charbuffer[20];
//存放沒有字節(jié)點的拼音;
p_e=father;
i=0;
BZW=0;
//printf("檢測的拼音為:%s\n",p);
while(p[i])
{
//printf("%c",p[i]);
i++;
}
i=0;
while(p[i])
//BZw用來控制跳出循環(huán)
{
//查找到實際有效的拼音長度
for(j=0;j<26;j++)
{
if(p[i]==T[j])
{
if(p_e->letter[j]!=NULL)
{
p_e=p_e->letter[j];
//printf("找到對應(yīng)的節(jié)點%c\n",p_e->ElementType);
i++;
break;
}
}
}
}
/*
printf("pointer當(dāng)前節(jié)點的字母為:%c",p_e->ElementType);
printf("找到實際位置:%c\n",p_e->ElementType);//測試用
printf("pointer的詞標志位值為:%d\n",p_e->Isword);
*/
py_longth=i;
if(py_longth!=0)
{
BZW=0;
//保留使用,不用可以注銷
i=0;j=0;k=0;
if(p_e->Isword==1)
{
p_ci=p_e->ci;
while(p_ci!=NULL)
//取詞
{
CH_CON[j][i]=p_ci->data;
i++;
if(i==9)
{
i=0;//列
j=j+1;//行
}
if(p_ci->next==NULL)
{
break;
}
else
{
p_ci=p_ci->next;
}
}
if(p_e->ch!=NULL)
{
p_ch=p_e->ch;
while(p_ch!=NULL)//取字,便于顯示;
{
CH_CON[j][i]=p_ch->data;
p_ch=p_ch->next;
i++;
if(i==9&&(p_ch->data!=NULL))
{
i=0;//列
j=j+1;//行
}
}
}
ROW_MAX=j;
//printf("字詞行數(shù)為:%d\n",ROW_MAX);
COLUMN_MIN=i;
//printf("最小列值為:%d\n",COLUMN_MIN);
}
else
{
if(p_e->ch!=NULL)
{
p_ch=p_e->ch;
while(p_ch!=NULL)//取字,便于顯示;
{
CH_CON[j][i]=p_ch->data;
p_ch=p_ch->next;
i++;
if(i==9&&(p_ch->data!=NULL))
{
i=0;//列
j=j+1;//行
}
}
ROW_MAX=j;
printf("字詞行數(shù)為:%d\n",ROW_MAX);
COLUMN_MIN=i;
printf("最小列值為:%d\n",COLUMN_MIN);
}
elseif(p_e->ch==NULL)
{
while(k<26)
{
if((p_e->letter[k]!=NULL)&&(p_e->letter[k]->ch!=NULL))
{
/*
memset(buffer,0,20);
strncpy(buffer,p,py_longth)
strcat(buffer,&T[k]);
*/
p_ch=p_e->letter[k]->ch;
while(p_ch!=NULL)//取字,便于顯示;
{
CH_CON[j][i]=p_ch->data;
p_ch=p_ch->next;
i++;
if(i==9)
{
i=0;//列
j=j+1;//行
}
}
ROW_MAX=j;
//printf("字詞行數(shù)為:%d\n",ROW_MAX);
COLUMN_MIN=i;
//printf("最小列值為:%d\n",COLUMN_MIN);
break;
}
k++;
}
}
}
if(ROW_MAX==0)//顯示變量的控制
{
k=COLUMN_MIN;
}
else
{
k=9;
}
memset(hanzi,0,60);
for(i=0;i<k;i++)
{
//printf("%d%s",(i+1),CH_CON[0][i]);
memset(label_swap,0,30);
sprintf(label_swap,"%d",(i+1));
strcat(label_swap,CH_CON[0][i]);
strcat(hanzi,label_swap);
}
gtk_label_set_label(GTK_LABEL(label_cn),hanzi);
}
else
gtk_label_set_label(GTK_LABEL(label_cn),"
");
}/*******************************************************************
函數(shù)名:button_click;
輸入?yún)?shù):GtkWidget*widget,gpointerdata;
輸出:void;
功能:按鍵的回掉函數(shù),實現(xiàn)對應(yīng)按鍵的功能;
********************************************************************/
voidbutton_click(GtkWidget*widget,gpointerdata)
{
charbuffer[30];//存放拼音的有效字母;
charzimu;
inti,j,n;
structElement*p_e;
p_e=father;
sprintf(&zimu,"%s",data);
//printf("輸入的字符為:%c\n",zimu);
if(islower(zimu))
{
//memset(buffer,0,30);
strcat(pin_y,&zimu);
//sprintf(buffer,pin_y);
i=0;n=0;
while(i<strlen(pin_y))
{
for(j=0;j<26;j++)
{
if(pin_y[i]==T[j])
{
if(p_e->letter[j]!=NULL)
{
p_e=p_e->letter[j];
n++;
}
}
}
i++;
}
if(i!=n)
{
memset(buffer,0,30);
strncpy(buffer,pin_y,n);
memset(pin_y,0,20);
sprintf(pin_y,buffer);
//printf("有效的拼音字母為:%s\n",buffer);
test_py(pin_y);
gtk_label_set_label(GTK_LABEL(label_py),pin_y);
}
else
{
test_py(pin_y);
gtk_label_set_label(GTK_LABEL(label_py),pin_y);
}
}
elseif(isdigit(zimu))
{
//printf("pin_y[0]的字母為:%c\n",pin_y[0]);
if(pin_y[0]!='\0')
{
//printf("通過首字母的比較判斷!\n");
if(SYMBOL==ROW_MAX)
{
//printf("通過行列值大小的比較判斷!\n");
//printf("%d\n",zimu);
i=(int)zimu-48;
if(i<=COLUMN_MIN)
{
//printf("輸入的數(shù)字%d通過最小行列值的比較!\n",zimu);
switch(zimu)
{
case'1':chose(pin_y,CH_CON[SYMBOL][0]);break;
//選擇
case'2':chose(pin_y,CH_CON[SYMBOL][1]);break;
case'3':chose(pin_y,CH_CON[SYMBOL][2]);break;
case'4':chose(pin_y,CH_CON[SYMBOL][3]);break;
case'5':chose(pin_y,CH_CON[SYMBOL][4]);break;
case'6':chose(pin_y,CH_CON[SYMBOL][5]);break;
case'7':chose(pin_y,CH_CON[SYMBOL][6]);break;
case'8':chose(pin_y,CH_CON[SYMBOL][7]);break;
case'9':chose(pin_y,CH_CON[SYMBOL][8]);break;
}
SYMBOL=0;
gtk_label_set_label(GTK_LABEL(label_yx),ci_buffer);
gtk_label_set_label(GTK_LABEL(label_py),"
");
memset(pin_y,0,20);
gtk_label_set_label(GTK_LABEL(label_cn),"
");
memset(hanzi,0,60);
}
}
else
{
switch(zimu)
{
case'1':printf("進入選擇\n");chose(pin_y,CH_CON[SYMBOL][0]);printf("完成選擇\n");break;
//選擇
case'2':chose(pin_y,CH_CON[SYMBOL][1]);break;
case'3':chose(pin_y,CH_CON[SYMBOL][2]);break;
case'4':chose(pin_y,CH_CON[SYMBOL][3]);break;
case'5':chose(pin_y,CH_CON[SYMBOL][4]);break;
case'6':chose(pin_y,CH_CON[SYMBOL][5]);break;
case'7':chose(pin_y,CH_CON[SYMBOL][6]);break;
case'8':chose(pin_y,CH_CON[SYMBOL][7]);break;
case'9':chose(pin_y,CH_CON[SYMBOL][8]);break;
}
SYMBOL=0;
gtk_label_set_label(GTK_LABEL(label_yx),ci_buffer);
gtk_label_set_label(GTK_LABEL(label_py),"
");
memset(pin_y,0,20);
gtk_label_set_label(GTK_LABEL(label_cn),"
");
memset(hanzi,0,60);
}
bl(father);
}
else
{
strcat(entry_buffer,&zimu);
gtk_entry_set_text(GTK_ENTRY(entry_all),entry_buffer);
}
}
}/*******************************************************************
函數(shù)名:button_left_click;
輸入?yún)?shù):GtkWidget*widget,gpointerdata;
輸出:void;
功能:按鍵的回掉函數(shù),左選功能;
********************************************************************/
voidbutton_left_click(GtkWidget*widget,gpointerdata)
//前翻頁
{
inti;
if(SYMBOL>=1)
{
SYMBOL=SYMBOL-1;
memset(hanzi,0,60);
for(i=0;i<9;i++)
{
//printf("%d%s",(i+1),CH_CON[SYMBOL][i]);
memset(label_swap,0,30);
sprintf(label_swap,"%d",(i+1));
strcat(label_swap,CH_CON[SYMBOL][i]);
strcat(hanzi,label_swap);
}
}
gtk_label_set_label(GTK_LABEL(label_cn),hanzi);
}/*******************************************************************
函數(shù)名:button_right_click;
輸入?yún)?shù):GtkWidget*widget,gpointerdata;
輸出:void;
功能:按鍵的回掉函數(shù),右選功能;
********************************************************************/
voidbutton_right_click(GtkWidget*widget,gpointerdata)
{
inti,k;
if(SYMBOL<ROW_MAX)
{
SYMBOL=SYMBOL+1;
if(SYMBOL==ROW_MAX)
{
k=COLUMN_MIN;
}
else
{
k=9;
}
memset(hanzi,0,60);
for(i=0;i<k;i++)
{
//printf("%d%s",(i+1),CH_CON[SYMBOL][i]);
memset(label_swap,0,30);
sprintf(label_swap,"%d",(i+1));
strcat(label_s
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 一章數(shù)與式五節(jié)二次根式
- 支模施工合同書范本
- 權(quán)威編寫印刷服務(wù)合同協(xié)議書
- 礦石購銷合同格式
- 花崗石室內(nèi)裝修合同
- 外賣服務(wù)合同簽訂注意事項全解析
- 毛巾床單采購合同
- 中介服務(wù)合同樣本樣式
- 退出合同協(xié)議的操作指南
- 編劇參與分成協(xié)議
- 中建西南院2024年招聘筆試參考題庫附帶答案詳解
- 信息委員競選稿
- 中國設(shè)計史-第四章-春秋戰(zhàn)國的設(shè)計
- 語文培優(yōu)補差工作計劃及措施
- 開源軟件社區(qū)治理模式
- (2024年)ESD靜電防護培訓(xùn)
- 《光伏發(fā)電工程安全驗收評價規(guī)程》(NB-T 32038-2017)
- 《冰淇淋種類及原料》課件
- 《網(wǎng)絡(luò)的運行和維護》課件
- 企業(yè)信息化建設(shè)戰(zhàn)略合作協(xié)議
- 初中地理七年級下冊《日本》教學(xué)課件11
評論
0/150
提交評論