Hi I have a couple of questions for the first app I am creating.

Firstly I am trying to have user input certain things, and it is not working correctly.

printf("Object : ");
	scanf("%04X", &code);
	printf("Message : ");
	scanf("%s", input);

Object is working perfectly, but then the Message I am trying to input... I am trying to do a string input (which could contain spaces), and I am only getting the first word (if there is a space).

The end result is to send the sting off to this:

void SendString(char* string);

I am trying to do it after the input like this:

SendText( pid, input);

incase your wondering about SendText, its:

void SendText ( UINT pid , char message[4096] ) 
{
	CKeyboardHelper* pKeyboardHelper;
	pKeyboardHelper = new CKeyboardHelper("WindowerMMFKeyboardHandler_4384");
	pKeyboardHelper->SendString(message);

	delete pKeyboardHelper;
}

Thanks in advance, any help is appreciated.

I'm going to assume scanf() is like cin in the way that it cannot take in spaces.
One way to use cin to take in spaces is to use getline(cin, variable).
Then use cin.ignore() if you run into a problem with the '\n' character skipping inputs afterward.

Hey I am trying to make console apps too, but I ahven't got very far :P

Would you feel comfortable sharing your code here so others can learn how to create a console app?

ps, um yeah sorry I dont have anything constructive to add to ur prob lol, making console apps is hard :(

You should use the following command which will scan for a string and put everything that has been written until the newline character (enter) is hit:

cin>>input;

cin goes till a ' ' or '\n' character comes up.
getline() goes until a '\n' character.

Alright, so I am told cin and cout are synced, so I need to be using them together. So I have changed to:

cout << "PID : ";
	std::cin >> testpid;
	cout << "Object : ";
	std::cin >> std::hex >> code;
	//scanf("%04X", &code);

	cout << "Message : ";
	getline(std::cin, input);

this does not error, but when I get to Message:, it does not prompt me for input, it just continues with nothing inputted.

cout << "Message : ";
	std:cin >> input;
        cin.ignore();
	getline(std::cin, input);
	//cin >> input;
	cout << input;

that now does accept input. thanks for that.

if i input "test test", it is only returning "test"

If you are tying in "test test" it will put test for the 1st input prompt and test for the second. And this will result in giving you a single output of test.

remove std:cin >> input; ( scope is :: not : ) and this should work.

yea, that was my mistake... didnt notice that in there. it is working now.

finally, one last thing.

the function I am trying to pass the string to is:

void SendString(char* string);

obviously a string wont pass to this. how would i go about doing this?

A way you can do this is use the function

void SendString(const char* string);

and if your input variable is a string type then for passing it into the function put

SendString(input.c_str())

this is what I am doing:

the main....
        string input;
	cout << "PID : ";
	std::cin >> testpid;
	cout << "Object : ";
	std::cin >> std::hex >> code;

	cout << "Message : ";
        cin.ignore();
	getline(std::cin, input);


int PopDetected ()
{
  time_t rawtime;
  struct tm * timeinfo;

  time ( &rawtime );
  timeinfo = localtime ( &rawtime );
  printf ( "Pop Detected: %s", asctime (timeinfo) );
  SendText(pid, input.c_str());
  return 0;
}

void SendText ( UINT pid , char* message ) 
{
	CKeyboardHelper* pKeyboardHelper;
	pKeyboardHelper = new CKeyboardHelper("WindowerMMFKeyboardHandler_4384");
	pKeyboardHelper->SendString(message);

	delete pKeyboardHelper;
}

error i am receiving is:
error C2664: 'SendText' : cannot convert parameter 2 from 'const char *' to 'char *'

Edited 7 Years Ago by joshk6656: n/a

By the looks of it you want to be working with cstrings instead of the "new" C++ strings.

#include <cstring>
int main(){
	char input[100];
	cin.getline(input,100);
	return 0;
}

With this you take in a char array from getline() instead of a string and are able to pass it through your function SendText.

Or you can fix it without changing as much code by making it so SendText() takes in a UINT and string for parameters.

And for both you would remove the .c_str() attribute from input.

(I see you have std::cin, std::hex but you do not have std::string or std::cout meaning you are using the namespace std. Once you start using namespace std then you do not have to keep setting the scope.)

By the looks of it you want to be working with cstrings instead of the "new" C++ strings.

#include <cstring>
int main(){
	char input[100];
	cin.getline(input,100);
	return 0;
}

With this you take in a char array from getline() instead of a string and are able to pass it through your function SendText.

Or you can fix it without changing as much code by making it so SendText() takes in a UINT and string for parameters.

And for both you would remove the .c_str() attribute from input.

(I see you have std::cin, std::hex but you do not have std::string or std::cout meaning you are using the namespace std. Once you start using namespace std then you do not have to keep setting the scope.)

sfuo, thanks for your help. it is much appreciated. I will give this a shot when i get home from work.

I do have another question, since I am not familar with this:

This line:

pKeyboardHelper = new CKeyboardHelper("WindowerMMFKeyboardHandler_4384");

4384 is manually set for now, but I am planning on passing testpid (UINT) to it. How would i go about joining the two using the variable?

I would take testpid in as a string or convert it to one and put

pKeyboardHelper = new CKeyboardHelper(("WindowerMMFKeyboardHandler_"+testpid).c_str());

This should work if not I'll look at another way.

oh i forgot to mention, same deal here:

void CKeyboardHelper(char* string);

I'm not 100% sure how you want to set up all your variables and parameters but here are a few things:
Use a character array (char var[]) for a parameter char* string.
For a const char* parameter and you want to use a c++ string then convert the string with .c_str() making it a const char* array.

You could make it work either way but you have to pick one and stick to it otherwise you are adding in lines of code to convert from one to another. Personally I would stick to C++ strings for this.

I'm not 100% sure how you want to set up all your variables and parameters but here are a few things:
Use a character array (char var[]) for a parameter char* string.
For a const char* parameter and you want to use a c++ string then convert the string with .c_str() making it a const char* array.

You could make it work either way but you have to pick one and stick to it otherwise you are adding in lines of code to convert from one to another. Personally I would stick to C++ strings for this.

well, i do not think i will be able to stick to the c++ strings for this, since the helper i am using is compiled, i will not be able to change the variable types.

well my string issue is fixed (as far as passing it to SendText and putting the PID with the helper). The problem now is this function:

DWORD GetFFXiAddr(UINT uPid);

is there an easy to to convert a char * input to uint?

Try the function atoi() it is not used by all compilers but you can see if it works. Or take the value in as an int and use itoa() for adding the number to the end of the string.
(itoa() converts int to string and atoi() is string to int)

Try the function atoi() it is not used by all compilers but you can see if it works. Or take the value in as an int and use itoa() for adding the number to the end of the string.
(itoa() converts int to string and atoi() is string to int)

alright i got everything working as i need. thanks a lot!!!

one more question....

char charname[100];
	cout << "Character Name : ";
	std::cin >> charname;
	if (charname != "Synergy") return;

I am looking to add something based on charname, if the charname DOES NOT EQUAL Synergy, exit. What is wrong with this?

use c++ function, cin.getline
here is an example

printf("enter your name: ");
 cin.getline (name,256);
This question has already been answered. Start a new discussion instead.