Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

"@help" function; maybe threading ?

$
0
0
im making a texted based rpg and i want to implement a help function. for example, if i type "/help" at anytime it will print out something or do something. at the same time runs all the function listed in the main function.
i have thought to create a separate thread but i got a bit confused when i typed in "/help" at a certain point it is clashing with the other functions waiting to input data so.

when i enter "/help" press enter it will do what is in the help function but if i enter "/help" press enter again it goes into an infinite loop

#include <string>
#include <iostream>
#include <Windows.h>
#include <process.h>

using namespace std;

unsigned __stdcall help(void*)
{
	string temp;
	cin>>temp;
	if(temp =="/help")
	Misc::debug("help function thread");//prints out the parameter
	return 0;
}

int main()
{

	HANDLE hThread;
	unsigned threadID;
	
	hThread = (HANDLE)_beginthreadex(NULL,0,&help,NULL,0,&threadID);
        int temp;
	cout<<"enter a number"<<endl;
        cin>>temp;
        cout<<temp;


	WaitForSingleObject(hThread, INFINITE);
	
	system("pause");
	_endthreadex(0);

	return 0;
}


Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>