使用puts输出C int是否有更短的方法?
我需要在基于USB(libusb)C的命令行实用程序中执行以下操作:
char pid[20]; sprintf(pid, "Product ID : %#06x", anInteger); puts(pid);
有没有更短的单行方式来做到这一点?
使用printf?
printf("Product ID : %#06x\n", descriptor.idVendor);
而不是使用sprintf
& puts
,只需更改为printf
:
printf("Product ID : %#06x", descriptor.idVendor);
不是使用puts …你可以使用printf,但是你不能将数据存储在pid变量中。 不幸的是,你无法双管齐下。 如果你在Linux上允许你注册一个自定义的printf格式(谷歌应该发现一些东西),你可以使用glibc扩展printf,但我不建议只保存一两行。