-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
53 lines (48 loc) · 1.04 KB
/
main.c
File metadata and controls
53 lines (48 loc) · 1.04 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
// 2018113528 심재헌
// main code file
#include <stdio.h>
#include <curses.h>
#include <signal.h>
#include <fcntl.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/wait.h>
#include "game.h"
int score=0; // score variable
int main(){
int pid = fork(); //start init_screen
int right;
int type=-1;
signal(SIGINT,SIG_IGN);
switch (pid) {
case -1: // error
perror("fork failed");
exit(1);
case 0: // run init_screen process
init_screen();
default:
break;
}
wait(NULL);
clear();
type=type_input(); // choose type
if(type==-1){ // wrong input
error_screen(); // go to error_screen
}
go_condition();
for(int i=0;i<Q_NUMBER;i++){ // 10 questions
right=question(i,score,type);
if(right==0){ // if wrong
game_over(score); // go to game_over
}else{ // if correct
score++; // plus score
if(score==Q_NUMBER){ // if all correct
all();
}else{
correct(score);
}
}
}
signal(SIGINT,SIG_DFL);
}