What does “%.*s” mean in printf?
You can use an asterisk (*) to pass the width specifier/precision to printf(), rather than hard coding it into the format string, i.e. void f(const char *str, int str_len) { printf(“%.*s\n”, str_len, str); }
You can use an asterisk (*) to pass the width specifier/precision to printf(), rather than hard coding it into the format string, i.e. void f(const char *str, int str_len) { printf(“%.*s\n”, str_len, str); }
You can use z for size_t and t for ptrdiff_t like in printf(“%zu %td”, size, ptrdiff); But my manpage says some older library used a different character than z and discourages use of it. Nevertheless, it’s standardized (by the C99 standard). For those intmax_t and int8_t of stdint.h and so on, there are macros you … Read more
They are the same when used for output, e.g. with printf. However, these are different when used as input specifier e.g. with scanf, where %d scans an integer as a signed decimal number, but %i defaults to decimal but also allows hexadecimal (if preceded by 0x) and octal (if preceded by 0). So 033 would … Read more
%lu is the correct format for unsigned long. Sounds like there are other issues at play here, such as memory corruption or an uninitialized variable. Perhaps show us a larger picture?
Use the ll (el-el) long-long modifier with the u (unsigned) conversion. (Works in windows, GNU). printf(“%llu”, 285212672);
“%f” is the (or at least one) correct format for a double. There is no format for a float, because if you attempt to pass a float to printf, it’ll be promoted to double before printf receives it1. “%lf” is also acceptable under the current standard — the l is specified as having no effect … Read more