如何将f整数123打印为12.3 [英] How to printf integer 123 as 12.3

查看:219
本文介绍了如何将f整数123打印为12.3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

printf(format,123)
如果只能更改格式部分,如何将123输出为12.3?

printf( format, 123 )
how to print 123 out as 12.3 if I can only change the format part?

推荐答案

这是一个非常有趣的问题.

怎么样呢?

您可以做到完美.
例如:
printf(setformat(),123);

那么您可以看到"12.3"的结果
请测试以下代码.

int faddr;
char * pempty;
__declspec(裸)char * setformat()
{
_asm mov eax,[esp + 04h];
_asm mov faddr,eax;
_asm pushad;
pempty =(char *)malloc(1);
* pempty = 0;
printf(%d.%d",faddr/10,faddr%10);
_asm popad;
_asm mov eax,pempty;
_asm ret;
}
int main(int argc,char * argv)
{
printf(setformat(),123);
返回0;
}


我认为这是您问题的完美答案.
This is very interesting problem.

How about this?

You can do that perfectly.
eg:
printf(setformat(),123);

then you can see the result of "12.3"
Please test below code.

int faddr;
char* pempty;
__declspec (naked) char* setformat()
{
_asm mov eax , [esp + 04h];
_asm mov faddr, eax;
_asm pushad;
pempty = (char*)malloc(1);
*pempty = 0;
printf("%d.%d", faddr/10, faddr%10);
_asm popad;
_asm mov eax, pempty;
_asm ret;
}
int main(int argc, char* argv)
{
printf(setformat(),123);
return 0;
}


I think that is perfect answer for your problem.


没有格式标志可以做到这一点.
int x=123; printf("%i.%i",x/10,x%10);
问候.
There is no format flag to do that.
int x=123; printf("%i.%i",x/10,x%10);
Regards.


为什么只能更改格式部分?您对其中带有printf的代码完全没有任何控制权吗?如果不是这样,除非您可以对其进行打印的流进行后续编辑,否则您可能会卡住.如果您可以更改printf语句/代码,则位于以下位置:

1.转换为双精度/除以10/打印双精度或

2.保留为整数,除以10得到12-打印-从123减去10乘以12得到3-并打印.
Why can you only change the format part? Do you not have any control at all over the code with the printf in it? If not, you are probably stuck unless you can do a subsequent edit on the stream it is printing to. If you can alter the printf statement / code it is in:

1. Convert to double / divide by 10 / print the double, or

2. Leave as integer, divide by 10 to get 12 - print that - take 10 times 12 away from 123 to get 3 - and print that.


这篇关于如何将f整数123打印为12.3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆