I am trying to convert an unsigned long long val = 0x1234567890123456; to a string "0x1234567890123456" but i am
not able to convert it even if i use "%llu" as format specifier with the code provided in code-section .
But I am able to convert an unsigned int val = 0x1234567A; to "0x1234567A".
Could you please let me know what i have to do to achieve this ?? Appreciate your help.
I want to convert an unsigned long long val = 0x1234567890123456; to a string "0x1234567890123456" with the below code.
#include <stdio.h> /* printf, NULL */
#include <stdlib.h> /* strtoul */
#include<conio.h>
#include<string.h>
#include<stdlib.h>
#include<wchar.h>
#include<iostream>
using namespace std;
int main ()
{
unsigned int val = 0x1234567A;
char result[255] = {0};
char formatStr[20] = {0};
char typeMod[2] = {0};
unsigned char precision=16;
sprintf(typeMod, "X");
char precisionMod[4] = {0};
if (precision > 0)
_snprintf(precisionMod, sizeof(precisionMod), ".%u", precision);
sprintf(formatStr, "%%%s%s%s", precisionMod, "", typeMod);
char* output = result;
sprintf(output, "0x");
output += 2;
sprintf(output, formatStr, val);
puts(result);
getch();
return 0;
}