[英]Is there a shorter way to output C int with puts?
我必須在正在編寫的基於USB(libusb)C的命令行實用程序中執行以下操作:
char pid[20];
sprintf(pid, "Product ID : %#06x", anInteger);
puts(pid);
有沒有更短的單線方法來做到這一點?
而不是使用sprintf
& puts
,只需更改為printf
:
printf("Product ID : %#06x", descriptor.idVendor);
使用printf?
printf("Product ID : %#06x\n", descriptor.idVendor);
不能與puts一起使用...您可以使用printf,但是不能將數據存儲在pid變量中。 不幸的是,您不能同時擁有這兩種方式。 如果您使用的是Linux,可以使用glibc擴展名對printf進行擴展,該擴展名允許您注冊自定義printf格式(Google應該啟用某種格式),但我不建議您僅保存一兩行。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.