C / C++ --> Need help with some text input.

Started by
2 comments, last by ryt 10 years, 5 months ago

Hii guys (:
I've been programming in c/c++ for about 6 - 8 month now, mostly game stuff, which might be why i'm asking this newbie question ^^
I got tired of playing around with SDL and Opengl efter a while, and i thought to myself "What do you want to achive with programming?", and i guess my answer was "it all" biggrin.png
But right now i'm making my own little kinda cmd chat, right now just for localhost.

My problem is getting the keystrokes converted to strings/words, so that it does not just buffer a single letter at the time, but submit the whole word or sesntence. i just deleted my whole project and started from scratch so this is all my code so far;


#include <iostream>
#include <windows.h>
#include <Winuser.h>
#include <time.h>
using namespace std;

int main()
{

	TCHAR pcName [250];
	TCHAR userName [250];
	DWORD pcSize = 20;
	DWORD userSize = 20;
	SYSTEMTIME st;
	GetLocalTime(&st);

	if(!GetComputerName(pcName,&pcSize))
	{
		cout << "Size: " << pcSize << "\tError Code: " << GetLastError() << std::endl;
	}
	if(!GetUserName(userName,&userSize))
	{
		cout << "Size: " << userSize << "\tError Code: " << GetLastError() << std::endl;
	}



	cout << "(";
	cout << st.wDay;
	cout << "/";
	cout << st.wMonth;
	cout << "/";
	cout << st.wYear;
	cout << " - ";
	cout << st.wHour;
	if((int)st.wMinute < 10)
	{
		cout << ":0";
	} else
		cout << ":";
	
	cout << st.wMinute;
	cout << ":";
	cout << st.wSecond;
	cout << ")";
	cout << " -> ";
	cout << pcName;
	cout << " -> ";
	cout << userName << endl;





	system ("PAUSE");
	return 0;
}

And in the other runs/tests i'v been using GetAsyncKeyState() to detect the keystrokes. Anybody have any lessons to teach me? biggrin.png
Thanks a lot on advantage. Sincerly Wunder..

Advertisement

Based on that little bit of code, I'd recommend this article.

In the future, when asking questions it's best to post what you've tried rather than everything but the part you're having a problem with. Asking for help with input and then posting code that has no attempt at input in it isn't the best approach.

If you're using c++ it's probable best not to be using character arrays. I tend to read lines into a stringstream, then spit them out into strings or numbers as needed.

Std library supports string class so I recommend using this instead of arrays.

This topic is closed to new replies.

Advertisement