Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello all,

I am trying to craft a Decimal to Hexadecimal converter for my serial port communication program. I have hit one stumbling block, I am having issues figuring out how to input the textbox value (user generated up to 99) into the char array. Any and all help is greatly appreciated.

How should I go about storing the textbox value into the char array?

Here is the code that works before mucking it up (granted "0x3F" is the only output here):
       int i=0;
char integer_string[] = "63";   //The 63 is the value that must change based on the entry from the user into the textbox aptly named "dec".
char hex_string[10] = "";
i = atoi (integer_string);
sprintf (hex_string, "0x%02X", i);
hex->Text = gcnew String(hex_string);






For anyone following at home, here is the end result of the code with solution in place:
int i=0;
i = Int32::Parse(dec->Text);
char hex_string[10] = "";
sprintf (hex_string, "0x%02X", i);
hex->Text = gcnew String(hex_string);
Posted
Updated 26-Jun-13 7:43am
v2

1 solution

Without passing through the character array, you might use:
C++
i = int32::Parse(dec->Text); // assuming your 'decimal' TextBox name is 'dec'
 
Share this answer
 
Comments
Bandzerf 26-Jun-13 13:13pm    
Correct me if I am wrong but that would convert the textbox data "dec" into a 32-bit integer, then store it in i.
Is there an additional step then to allow the "integer_string" to be equal to that value "i"? The now 32-bit integer and character array do not mesh well, at least not when I attempt to debug it.
CPallini 26-Jun-13 13:34pm    
You don't need the 'additional step' (you don't need the integer_int array either), just go on with
sprintf (hex_string, "0x%02X", i); ...
Bandzerf 26-Jun-13 13:38pm    
Works flawlessly, Thank you!
CPallini 26-Jun-13 14:19pm    
You are welcome.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900