-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy paththread_game.c
More file actions
65 lines (63 loc) · 1.56 KB
/
thread_game.c
File metadata and controls
65 lines (63 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <stdio.h>
#include <stdlib.h>
#include <ncurses.h>
#include <unistd.h>
#include <pthread.h>
void *print_func (void * arg)
{
char buffer;
fread(&buffer, 1, 1, arg);
while (!feof(arg))
{
printw("%c", buffer);
usleep(10000);
fread(&buffer, 1, 1, arg);
refresh();
}
refresh();
pthread_exit(NULL);
}
int main()
{
initscr();
printw("Enter the path to the file \n"); /*путь до файла, мои превосходные знания английского*/
char filename[80];
getstr(filename);
FILE * file = fopen(filename, "r");
if (file==NULL)
{
printw("Ошибка при открытии файла");
return 1;
}
else printw("C - start/continue\nS - pause\nQ - quit \n\n");
/*C - начать/продолжить работу S - поставить программу на паузу Q - выход из программы*/
pthread_t print;
int buf = getch();
printw("\n");
bool work = false;
while (1)
{
if (work == false && (buf=='c' || buf=='C'))
{
pthread_create(&print, NULL, print_func, file);
work = true;
}
if (buf=='s' || buf=='S')
{
pthread_cancel(print);
work = false;
}
if (buf=='q' || buf=='Q')
{
pthread_cancel(print);
break;
}
buf = getch();
printw("\n");
}
pthread_join(print, NULL);
refresh();
system("pause");
endwin();
return 0;
}