steve_bank
Diabetic retinopathy and poor eyesight. Typos ...
Variable argument functions.
Neither cout nor printf() will print __int128 integers.
Not to worry, you can build your own printf(). I found the integer print function on the net when looking at __int128 numbers.
Writing a parser to parser a format string with arbitrary text and to handle number format display precision as printf() does would take some work. I put text in separate strings.
Neither cout nor printf() will print __int128 integers.
Not to worry, you can build your own printf(). I found the integer print function on the net when looking at __int128 numbers.
Writing a parser to parser a format string with arbitrary text and to handle number format display precision as printf() does would take some work. I put text in separate strings.
Code:
void print_int128(__int128 x) {
// source -- https://codeforces.com/blog/entry/75044
if (x < 0) {
putchar('-');
x = -x;
}
if (x > 9) print_int128(x / 10);
putchar(x % 10 + '0');
}//print_int128()
void xprintf(const char *fmt, ...){
va_list args;
va_start(args, fmt);
while (*fmt != '\0') {
if(*fmt == 's') {
string s = va_arg(args, string);
cout<<s;
}//if
if(*fmt == 'd') {
int n = va_arg(args, int);
cout<<n;
}//if
if(*fmt == 'f') {
double d = va_arg(args, double);
cout<<d;
}//if
if(*fmt == 'k'){
__int128 x = va_arg(args,__int128);
print_int128(x);
}
if(*fmt == '\n') {
cout<<endl;
}//if
++fmt;
}//while
va_end(args);
}//xprintf()
int main()
{
char format[20] = {"%s%d%s%f%s%k\n"};
string s1 = " int ";
string s2 = " double ";
string s3 = " int 128 ";
int a =1234;
double b = 1.234;
__int128 c = 12345678;
xprintf(format,s1,a,s2,b,s3,c);
return 0;
}