提交 61d4a391 编写于 作者: 当我不存在's avatar 当我不存在

更新main.c, GUI.py, NAME.name

上级
import os
import tkinter as tk #导入tkinter库
GUI = tk.Tk() #创建窗体,名为GUI
def reaction(event):
aaa = os.popen("main.exe")
result.delete('1.0','end')
result.insert('end', aaa.read())
result = tk.Text(GUI, height = 1, width = 8)
result.pack()
whether_to_continue = tk.Button(GUI, text = "next")
whether_to_continue.pack()
aaa = os.popen("main.exe")
result.insert('end', aaa.read())
while(True):
whether_to_continue.bind("<Button-1>", reaction)
GUI.mainloop()
1
2
3
4
5
6
7
8
9
10
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main() {
char ch; //记行数用
int quit = 1; //输出while循环是否退出(0退出,非0继续循环)
int mumber_number = 0; //文件行数
FILE* fp = fopen(".\\NAME.name", "r"); //二进制读打开NAME.name
if ((fp = fopen(".\\NAME.name", "r")) == NULL) { //如果文件不存在
printf("Error :) There is no file named 'NAME.name'"); //输出错误原因
return -1; //退出程序
}
//记算行数
while ((ch = fgetc(fp)) != EOF) { //文件读取完后退出循环
if (ch == '\n') { //读取到换行符时进入if
mumber_number++; //行数加一
}
}
char name[60][20]; //用来储存名字,60个名字,每个名字不大于20位
//开始存名字
fseek(fp, 0, 0); //光标回到文件开头
while ((ch = fgetc(fp)) != EOF) { //文件读取完毕后退出循环
int line = 0;
for (line = 0; line <= mumber_number; line++) { //line指读取到的行数
fscanf(fp, "%s", &name[line][0]); //存入name
}
}
fclose(fp); //关闭文件
//
int who = 0; //作为被抽者的数组下表
srand((unsigned)time(NULL)); //刷新种子
who = rand() % (mumber_number + 1); //产生1-50的随机数
printf("%s", name[who]); //输出结果
return 0; //退出,返回1
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册