Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to get hex correctly.

Status
Not open for further replies.

shamuntoha

Programmer
Dec 28, 2008
1
BE
How to get the output 0X33 not 0X334 ? (gcc compiler)

code:
#include <cstdlib>
#include <iostream>
#include <string>

using namespace std;


int main(int argc, char *argv[])
{

int arr[256] = {1,0x23,0x6C,0x1,0x2};
string leg1 = "324856789";

int leg2 = leg1.length();
for (int i=5; i < leg2+5; i ++ ) {
arr = printf("%#X",leg1[i-5]);
cout << arr << "\n";
}
system(PAUSE);
return 0;
}

 
> cout << arr << "\n";
Just delete this line.


--
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top