⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mycounter.c~

📁 linux 人品计算器
💻 C~
字号:
#include <gtk/gtk.h>#include <stdio.h>#include <stdlib.h>GtkWidget *window;	GtkWidget *label1,*label2,*label3;	GtkWidget *input1,*input2,*output;    	GtkWidget *button_check,*button_file;	GtkWidget *table;		void closeApp(GtkWidget *window,gpointer data){	gtk_main_quit();}void countFile(GtkWidget *widget,gpointer data){	FILE *input,*output;	const gchar *fileName;	int score=0;	char c;	char percent='%';	fileName=gtk_entry_get_text(GTK_ENTRY(input2));	output=fopen("result.txt","a");	if((input=fopen(fileName,"r"))==NULL)	{		printf("cannot open file\n");	}	printf("opened file\n");	//fprintf(output,"the file output %c",percent);	while(c!=EOF)	{		c=fgetc(input);		//printf("c==%c\n",c);		//printf(">>>>>score==%d\n",score);		if(c=='\n')		{	//printf("c is enter!\n");			fprintf(output,"%d%c\n",score,percent);			score=0;		}		else		{			if((int)c>64&&(int)c<91)			score+=(int)c-64;		}			}		fclose(input);		fclose(output);}void countWord(GtkWidget *widget,gpointer data){	const gchar *word;//定义数组	gint score=0;	gchar percent='%';	gchar *result;	gint i;	word=gtk_entry_get_text(GTK_ENTRY(input1));	for(i=0;word[i]!='\0';i++)	{		if((gint)word[i]>64&&(gint)word[i]<91)//ASCII码的值			score+=(gint)word[i]-64;		else score=0;	}		result=(gchar*)g_strdup_printf("%d%c",score,percent);	//result+=(gchar*)g_strdup_printf("%");//把单词的值付给result	gtk_entry_set_text((GtkEntry*)output,result);}int main(int argc,char *argv[]){    		gtk_init(&argc,&argv);	window=gtk_window_new(GTK_WINDOW_TOPLEVEL);	gtk_window_set_title(GTK_WINDOW(window),"单词数值计算器");	gtk_window_set_default_size(GTK_WINDOW(window),300,200);				label1=gtk_label_new("请输入单词:");	label2=gtk_label_new("单词的值为:");	label3=gtk_label_new("请输入文件路径:");	button_check=gtk_button_new_with_label("计算");	button_file=gtk_button_new_with_label("确定");	input1=gtk_entry_new();	input2=gtk_entry_new();	output=gtk_entry_new();	table=gtk_table_new(6,3,FALSE);	gtk_table_attach(GTK_TABLE(table),label1,0,1,0,1,GTK_FILL,GTK_FILL,8,8);	gtk_table_attach(GTK_TABLE(table),input1,0,2,1,2,GTK_FILL,GTK_FILL,8,8);	gtk_table_attach(GTK_TABLE(table),button_check,2,3,1,2,GTK_FILL,GTK_FILL,8,8);	gtk_table_attach(GTK_TABLE(table),label2,0,1,2,3,GTK_FILL,GTK_FILL,8,8);	gtk_table_attach(GTK_TABLE(table),output,1,3,2,3,GTK_FILL,GTK_FILL,8,8);    	gtk_table_attach(GTK_TABLE(table),label3,0,1,4,5,GTK_FILL,GTK_FILL,8,8);	gtk_table_attach(GTK_TABLE(table),input2,0,2,5,6,GTK_FILL,GTK_FILL,8,8);	gtk_table_attach(GTK_TABLE(table),button_file,2,3,5,6,GTK_FILL,GTK_FILL,8,8);	g_signal_connect(GTK_OBJECT(window),"destroy",GTK_SIGNAL_FUNC(closeApp),NULL);	g_signal_connect(GTK_OBJECT(button_check),"clicked",GTK_SIGNAL_FUNC(countWord),NULL);	g_signal_connect(GTK_OBJECT(button_file),"clicked",GTK_SIGNAL_FUNC(countFile),NULL);	//gtk_entry_set_text((GtkEntry*)output,"output");	gtk_container_add(GTK_CONTAINER(window),table);	gtk_widget_show_all(window);	gtk_main();	return 0;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -