All Questions
152 questions
1
vote
2
answers
96
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 = ...
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&...
1
vote
2
answers
162
views
Is it undefined behaviour to use the incorrect format specifiers when bits were masked away
If I have some imaginary uint32_t and I am interested in looking at each byte is it undefined behaviour to use the format specifier for a uint8_t rather than a uint32_t. See below for an example of ...
4
votes
1
answer
3k
views
On which systems/platforms is "%b" supported as a format specifier?
I know that at least some implementations of printf() (or sprintf() etc.) support a %b format specifier, which formats integral numbers using binary digits. But - this does not seem to be part of the ...
1
vote
2
answers
725
views
Printing with format specifiers in C
In a class quiz, I was asked to write the output of the below code snippet.
x = 1.234;
printf("x=%2d");
The variable x contains point values so I assumed it to be a float/double type.
In ...
0
votes
3
answers
750
views
Using %d with char , unexpected results
Text editor : VS code
Compiler : minGW
I was needed to store a number between 1-10, so I thought why don't store it in a char variable because it takes only 1 byte.
so, look at the following code
char ...