Visual C ++ 6.0 with unsigned long long and sprintf

I want sprintf () to be an unsigned long long value in visual C ++ 6.0 (plain C).

char buf[1000]; //bad coding unsigned __int64 l = 12345678; char t1[6] = "test1"; char t2[6] = "test2"; sprintf(buf, "%lli, %s, %s", l, t1, t2); 

gives the result

 12345678, (null), test1 

(see test2 not printing)

and l = 123456789012345 it gives an exception descriptor

any suggestions?

+4
source share
3 answers

To print the unsigned __int64 in Visual C ++ 6.0, you must use %I64u , not %lli (see this page on MSDN). %lli is only supported in Visual Studio 2005 and later. So your code should be:

 sprintf(buf, "%I64u, %s, %s", l, t1, t2); 
+9
source

printf uses ellipsis to pass a list of variable arguments. (Zero) that you see is the second part of your long time, which, as it turns out, is only 0 bits. Set it to 1 <60 ± plus 1 <30, and you will receive a loss of the crash when the 1 <<60 part is interpreted as char *.

The correct solution is to break the three-part number into 10 digits: "verylongvalue% 1 000 000 000" "(very longvalue / 1 000 000 000)% 1 000 000 000" "very longvalue / 1 000 000 000 000 000 000 000".

+1
source

Apparently, you did not assign additionaltext required char * (string). Note that the long int processed, the comma was copied and only %s generated (null) .

-1
source

Source: https://habr.com/ru/post/1277722/


All Articles