Jump to content
  • Advertisement
Sign in to follow this  
phil05

Need some advice on this code

This topic is 5072 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I click on new game, and a character generation dialog pops up, so I enter my information and forget to enter my age on it. I press the "done" button and it should alert saying that my age has not been defined. Apparently it is not doing that. Any idea why?
// bAge = buffer for Age (char array)
// pcAge = unsigned short int that the buffer converts into.
unsigned short int pcAge = 0;
char bName[30];
char bAge[15];
	
// Pressing "Done" and does an error check.
						SendDlgItemMessage(dWnd, IDC_PCAGE, WM_GETTEXT, sizeof(bAge), (LPARAM)bAge);
							pcAge = unsigned short int(bAge);	
							
							/* Error Check -> If pcAge is empty, alert user and return TRUE */
							if (pcAge < 1)
							{
								MessageBox(NULL, "Please Enter Your Age", "Error", MB_OK);
								return TRUE;
							}


Share this post


Link to post
Share on other sites
Advertisement
Can't convert a C string to an integer that represents that value by using a cast. You have to use a function like atoi to do this.

Share this post


Link to post
Share on other sites
Happy birthday ;-)


#include <sstream>
#include <iostream>

int main() {

char age[] = { '1', '5', '0', '\0' };

std::stringstream ss(age);

int a = 0;

ss >> a;

std::cout << a << '\n';

return 0;
}





Your 150 today

[Edited by - snk_kid on August 5, 2004 2:41:01 PM]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!