Home  >  Article  >  Backend Development  >  How To Print a uint64_t Value Using printf Without the "spurious trailing '%' in format" Error?

How To Print a uint64_t Value Using printf Without the "spurious trailing '%' in format" Error?

DDD
DDDOriginal
2024-11-14 14:56:02231browse

How To Print a uint64_t Value Using printf Without the

Printing uint64_t with printf

When attempting to print a uint64_t using the printf function, you may encounter the error message "spurious trailing '%' in format". This error is caused by a trailing percent sign (%) in the format string provided to printf. To resolve this issue, follow these steps:

  1. Ensure the header is included in your code. This header defines the PRIu64 macro, which provides the correct format specifier for uint64_t.
  2. Add the macro definition __STDC_FORMAT_MACROS before including . This macro is necessary to enable the definition of the PRIu64 macro.
#define __STDC_FORMAT_MACROS
#include <inttypes.h>
  1. Use the %" PRIu64 " format specifier when passing a uint64_t variable to printf.
uint64_t ui64 = 90;
printf("test uint64_t : %" PRIu64 "\n", ui64);

By following these steps, you can correctly print a uint64_t value using printf without encountering the "spurious trailing '%' in format" error.

The above is the detailed content of How To Print a uint64_t Value Using printf Without the "spurious trailing '%' in format" Error?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn