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 = 100L;
printf("%lus", microseconds);
only prints 100s
because the u
is combined with the %l
and it interprets the format specifier as an unsigned long
instead of a long
%l
is not a complete format specification by itself. It might work by accident on some C libraries but it's incorrect to rely on that. Always give complete format specifications (in this case you wanted%ld
) and you won't have this problem. – Onlybegottenprintf
may crash or print nonsense if you don't always do that. I can make that a proper answer later when I'm on a real computer. – OnlybegottenL
in100L
serves little purpose. – Speciosity