printf

Setting count of decimal digits in printf at runtime in C language

有些话、适合烂在心里 提交于 2020-08-10 23:11:59
问题 I have a number: m which is given by the user as parameter. For example: m = 5 or m = 7 I do not know this at run-time. I then compute an integral and save it to a variable: answer . I want to print answer with m decimals digits. How can I do this? I tried this one: printf("answer = %(%.mf)d ", answer , m); It's wrong ,I know ,but how can I solve it? 回答1: If you have a variable with a value, say: double val = 3.234003467; You could print out to the 2nd decimal place for example using: printf(

Setting count of decimal digits in printf at runtime in C language

我的梦境 提交于 2020-08-10 23:10:13
问题 I have a number: m which is given by the user as parameter. For example: m = 5 or m = 7 I do not know this at run-time. I then compute an integral and save it to a variable: answer . I want to print answer with m decimals digits. How can I do this? I tried this one: printf("answer = %(%.mf)d ", answer , m); It's wrong ,I know ,but how can I solve it? 回答1: If you have a variable with a value, say: double val = 3.234003467; You could print out to the 2nd decimal place for example using: printf(

printf doesn't work for floats in LLVM IR

我是研究僧i 提交于 2020-08-10 03:37:12
问题 I want to print the value of a floating point variable to the screen. I am declaring printf() function in the LLVM IR code, and it is linking in successfully. Whenever I print an integer or a character data type, or a string, printf() prints them normally to the screen as it prints them in the C code. However, if I pass a float to printf() , instead of printing the floating point number, it prints 0.000000 . I checked the source code multiple times and it seems that the syntax is correct. It

How to convert date format using bash and printf?

…衆ロ難τιáo~ 提交于 2020-08-08 05:48:12
问题 I want to convert 2019-02-16 to Feb 16 15:29 in bash using awk and printf . For example: [root@localhost ~]# who | awk '{print $1, $3, $4}' root 2019-02-16 15:29 root 2019-02-16 15:30 john 2019-02-01 10:34 emmett 2019-01-12 09:45 Desired output: root Feb 16 15:29 root Feb 16 15:30 john Feb 1 10:34 emmett Jan 12 09:45 Please help and provide an explanation with your solution. 回答1: With any awk in any shell on any UNIX box: $ who | awk '{split($3,d,/-/); print $1, substr(