All Questions
Tagged with printf format-specifiers
169 questions
1
vote
1
answer
117
views
printf format specifier %h; is it standard?
Commands
printf 'ABC$def%hx\n' 10 # output: ABC$defa
printf 'ABC$def%s\n' 10 # output: ABC$def10
work as expected.... but I cannot find any info about %h.
Is it available on all systems?
-3
votes
2
answers
120
views
C++ format specifiers in custom functions
Is it possible in C++ to use format specifiers in a custom function?
Like as in the printf() statement, and how you can use e.g. '%d' to insert an int variable:
printf("The number is %d", ...
1
vote
2
answers
94
views
How to combine significant figures, column width, and alignment specifiers?
I would like to print doubles with consistent column width. Theses numbers represent dollar values so I would also like to have no more than two digits after the decimal print.
Here I'm intending to ...
2
votes
1
answer
247
views
Why isn't the %F format specifier working with printf?
I'm encountering an issue while using the printf() function and I'd like to share the details. The two main sources I'm referring to, cplusplus.com and cppreference.com, indicate that I can use the %f ...
0
votes
4
answers
200
views
Why does the printf("%c", 0.21) results in 'ß'?
So, here's my C code. While I was toying with my code in order to learn the format specifiers, especially %c:
#include <stdio.h>
void main()
{
double a = 0.21;
printf("%c", a);...
0
votes
2
answers
256
views
print as HEX (0x) or Decimal depending on value without if statements - how to?
I am trying to print an integer and its formatting should be %d decimal unless its of value FFFF in which case it should be printed as 0xFFFF. I am unable to do so without unnecessary if and else ...
1
vote
1
answer
255
views
Where are the format specifiers implemented/defined in the C language?
I have been working in C for a couple months now and it has never come to my mind to check where actually the format specifiers implemented/defined in the C language format specifiers like:
%f
%d
%p
%...
1
vote
2
answers
2k
views
How to print hexadecimal values in "0x" format in C
I am trying to print hexadecimal values in C.
A simple known program to print hexadecimal value...( Using %x or %X format specifier)
#include<stdio.h>
int main()
{
unsigned int num = 10;
...
6
votes
2
answers
201
views
Interpreting the format specifier in printf("%# 01.1g",9.8)
Consider the following printf instruction:
printf("%# 01.1g", 9.8);
what should it print?
I'm reading the description of the g specifier on cppreference.com, which says (text for G removed):...
-1
votes
1
answer
57
views
Malloc Array, trouble printing in new function in C [duplicate]
Hi I've created an array and used malloc to store it so it could use it in a different function but now I'm running into problems with printing the array as it says:
warning: format '%d' expects ...
5
votes
2
answers
406
views
How to separate format specifiers from characters with printf
Another way to phrase this question might be "How to end format specifiers in printf"
If I want to print microseconds in this format 100us using the following code...
long microseconds = ...
-2
votes
1
answer
463
views
%X format specifier prints value only up to 4 bytes?
Hex value of 6378624653 is : 0x17C32168D
But this code prints : 0x7C32168D
#include<iostream>
int main()
{
int x = 6378624653;
printf("0x%x", x);
}
can anyone explain why ...
0
votes
0
answers
195
views
Why doesn't zero padding with integers work in Matlab formatSpec?
I am trying to pad a number with zeros as follows.
Desired:
7 -> '07'
8 -> '08'
(In case it matters, the input is intended as a character vector to be converted by num2str. But for the examples ...
0
votes
2
answers
145
views
Differing output with printf using %d and %i
I found questions about %i and %d on here, but all of them seemed to claim that they were the same in printf.
Compiler: Apple clang version 12.0.5 (clang-1205.0.22.9)
Note: 15 is 017 in octal and 0xf ...
1
vote
2
answers
734
views
Meanning of %! and %K with printf
I try to rewrite printf function and i found a strange result when use format specifier (%) with ! or K. I want to understand why i get this result.
printf("%!");
printf("%K&...