#include<gtk/gtk.h>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
const char*danci="dd";
GtkWidget*dancizhib_label;
GtkWidget*wjlj_entry;
void closeApp(GtkWidget*window,gpointer data){
gtk_main_quit();
}
void jisuan_clicked(GtkWidget*window,gpointer data){
const char *danci_text=gtk_entry_get_text(GTK_ENTRY((GtkWidget*)data));
char sum=0,all[50];
int i;
for(i=0;danci_text[i]!=0;i++)
sum+=danci_text[i]-64;
sprintf(all,"%d",sum);
strcat(all,"%");
gtk_label_set_text(GTK_LABEL (dancizhib_label),all);
}
void zhixing_clicked(GtkWidget*window,gpointer data){
const char *filepath=gtk_entry_get_text(GTK_ENTRY((GtkWidget*)data));
FILE *fp,*fp2;
char i[50],sum=0,all[50],af[50];
int c,k,aa=0;
if((fp=fopen(filepath,"rb"))==FALSE)
{gtk_entry_set_text(GTK_ENTRY(wjlj_entry),"此路径文件不存在!");
return;
}
if((fp2=fopen("result.txt","wb"))==FALSE)
{gtk_entry_set_text(GTK_ENTRY(wjlj_entry),"result.txt文件不存在!");
return;
}
else
{
while((fscanf(fp,"%s",i))!=EOF)
{
for(c=0;i[c]!=0;c++)
sum+=i[c]-64;
sprintf(all,"%d",sum);
strcat(all,"%\n");
fprintf(fp2,"%s",all);
sum=0;
gtk_entry_set_text(GTK_ENTRY(wjlj_entry),"执行成功,已写入result.txt!");
}
}
rewind(fp);
rewind(fp2);
fclose(fp2);
fclose(fp);
}
int main(int argc,char *argv[]){
GtkWidget*window;
GtkWidget*danci_label,*dancizhi_label,*wjlj_label,*part_label;
GtkWidget*danci_entry;
GtkWidget*jisuan_button;
GtkWidget*zhixing_button;
GtkWidget*hbox1,*hbox2,*hbox3,*hbox4,*hbox5,*hbox6;
GtkWidget*vbox;
gtk_init(&argc,&argv);
window=gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(window),"单词数值计算器");
gtk_window_set_position(GTK_WINDOW(window),GTK_WIN_POS_CENTER);
gtk_window_set_default_size(GTK_WINDOW(window),450,250);
danci_label=gtk_label_new("请输入单词值:");
dancizhi_label=gtk_label_new("该单词值: ");
wjlj_label=gtk_label_new("请输入文件路径:");
dancizhib_label=gtk_label_new("0");
part_label=gtk_label_new("***************************************************************");
danci_entry=gtk_entry_new();
wjlj_entry=gtk_entry_new();
jisuan_button=gtk_button_new_with_label("计算");
zhixing_button=gtk_button_new_with_label("执行");
g_signal_connect(GTK_OBJECT(window),"destroy",GTK_SIGNAL_FUNC(closeApp),NULL);
g_signal_connect(GTK_OBJECT(jisuan_button),"clicked",GTK_SIGNAL_FUNC(jisuan_clicked),danci_entry);
g_signal_connect(GTK_OBJECT(zhixing_button),"clicked",GTK_SIGNAL_FUNC(zhixing_clicked),wjlj_entry);
hbox1=gtk_hbox_new(TRUE,10);
hbox2=gtk_hbox_new(TRUE,10);
hbox3=gtk_hbox_new(TRUE,10);
hbox4=gtk_hbox_new(TRUE,10);
hbox5=gtk_hbox_new(TRUE,10);
hbox6=gtk_hbox_new(TRUE,10);
vbox=gtk_vbox_new(FALSE,20);
gtk_box_pack_start(GTK_BOX(hbox1),danci_label,TRUE,FALSE,10);
gtk_box_pack_start(GTK_BOX(hbox2),danci_entry,TRUE,FALSE,1);
gtk_box_pack_start(GTK_BOX(hbox2),jisuan_button,TRUE,FALSE,9);
gtk_box_pack_start(GTK_BOX(hbox3),dancizhi_label,TRUE,FALSE,5);
gtk_box_pack_start(GTK_BOX(hbox3),dancizhib_label,TRUE,FALSE,5);
gtk_box_pack_start(GTK_BOX(hbox6),part_label,TRUE,FALSE,10);
gtk_box_pack_start(GTK_BOX(hbox4),wjlj_label,TRUE,FALSE,10);
gtk_box_pack_start(GTK_BOX(hbox5),wjlj_entry,TRUE,FALSE,5);
gtk_box_pack_start(GTK_BOX(hbox5),zhixing_button,TRUE,FALSE,5);
gtk_box_pack_start(GTK_BOX(vbox),hbox1,FALSE,FALSE,10);
gtk_box_pack_start(GTK_BOX(vbox),hbox2,FALSE,FALSE,10);
gtk_box_pack_start(GTK_BOX(vbox),hbox3,FALSE,FALSE,10);
gtk_box_pack_start(GTK_BOX(vbox),hbox6,FALSE,FALSE,10);
gtk_box_pack_start(GTK_BOX(vbox),hbox4,FALSE,FALSE,10);
gtk_box_pack_start(GTK_BOX(vbox),hbox5,FALSE,FALSE,10);
gtk_container_add(GTK_CONTAINER(window),vbox);
gtk_widget_show_all(window);
gtk_main();
return 0;
}
piikee
- 粉丝: 15
- 资源: 13
最新资源
- 東耳篮球馆会员信息管理系统(编号:98721117).zip
- 房屋系统(编号:45266146).zip
- 大学生志愿者信息管理系统(编号:96654262).zip
- 房屋租赁系统(编号:49930163).zip
- 付费自习室管理系统(编号:46724236)(1).zip
- 学术论文撰写技巧:施一公提高英文论文写作能力的六点建议
- 科研真问题从何而来-中科院院士分享
- 通过matlab语言读取csv文件.zip
- 通过Django实现用户注册和登录的简单认证系统.zip
- 通过汇编语言计算两个整数和,将结果存储在另一个变量中.zip
- Aruba%20Instant%20On_2.3.0_apk-dl.com.apk.1.1
- Ruby参考手册中文CHM版最新版本
- RubyonRails字符串处理中文最新版本
- 基于 selenium 模拟微博登录爬虫资料齐全+详细文档+源码.zip
- 基于chromeDriver+selenium蓝桥杯题库爬虫资料齐全+详细文档+源码.zip
- 基于java+selenium爬虫资料齐全+详细文档+源码.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
- 1
- 2
前往页