From 7c9d27cb03680bed8161c7ea48fc5df0eea66177 Mon Sep 17 00:00:00 2001 From: Olivia Appleton Date: Thu, 15 Aug 2024 20:56:41 -0500 Subject: [PATCH] make printf formatting portable --- c/src/include/utils.h | 3 ++- c/src/p0000_template.c | 3 ++- c/src/p0001.c | 3 ++- c/src/p0002.c | 3 ++- c/src/p0003.c | 3 ++- c/src/p0004.c | 3 ++- c/src/p0005.c | 3 ++- c/src/p0006.c | 3 ++- c/src/p0007.c | 3 ++- c/src/p0008.c | 3 ++- c/src/p0009.c | 3 ++- c/src/p0010.c | 3 ++- c/src/p0011.c | 3 ++- c/src/p0012.c | 3 ++- c/src/p0013.c | 3 ++- c/src/p0014.c | 3 ++- c/src/p0015.c | 3 ++- c/src/p0016.c | 3 ++- c/src/p0017.c | 3 ++- c/src/p0020.c | 3 ++- c/src/p0022.c | 3 ++- c/src/p0025.c | 3 ++- c/src/p0030.c | 3 ++- c/src/p0034.c | 3 ++- c/src/p0076.c | 3 ++- c/src/p0836.c | 1 + cplusplus/src/include/math.h | 1 + cplusplus/src/include/utils.h | 3 ++- 28 files changed, 54 insertions(+), 26 deletions(-) diff --git a/c/src/include/utils.h b/c/src/include/utils.h index 7ba65a09..4fc0d033 100644 --- a/c/src/include/utils.h +++ b/c/src/include/utils.h @@ -1,4 +1,5 @@ #pragma once +#include #include #include #include @@ -89,7 +90,7 @@ char *get_data_file(const char *name) { const size_t ret_code = fread(buffer, 1, length, file); if (ret_code != length) { if (feof(file)) - printf("Error reading %s: unexpected end of file, read %lu of %lu bytes expected\n", name, (uint64_t)ret_code, (uint64_t)length); + printf("Error reading %s: unexpected end of file, read %" PRIu64 " of %"PRIu64" bytes expected\n", name, (uint64_t)ret_code, (uint64_t)length); else if (ferror(file)) perror("Error reading data file"); } diff --git a/c/src/p0000_template.c b/c/src/p0000_template.c index 67fead69..c6f33a88 100644 --- a/c/src/p0000_template.c +++ b/c/src/p0000_template.c @@ -10,6 +10,7 @@ This paragraph should be replaced by the problem description, excluding images. #ifndef EULER_P0000 #define EULER_P0000 #include +#include #include uint64_t p0000() { @@ -18,7 +19,7 @@ uint64_t p0000() { #ifndef UNITY_END int main(int argc, char const *argv[]) { - printf("%lu\n", p0000()); + printf("%" PRIu64 "\n", p0000()); return 0; } #endif diff --git a/c/src/p0001.c b/c/src/p0001.c index ca936876..327ddaeb 100644 --- a/c/src/p0001.c +++ b/c/src/p0001.c @@ -15,6 +15,7 @@ #ifndef EULER_P0001 #define EULER_P0001 #include +#include #include #include "include/iterator.h" @@ -34,7 +35,7 @@ uint64_t p0001() { #ifndef UNITY_END int main(int argc, char const *argv[]) { - printf("%lu\n", p0001()); + printf("%" PRIu64 "\n", p0001()); return 0; } #endif diff --git a/c/src/p0002.c b/c/src/p0002.c index 30c222f8..ac08ceeb 100644 --- a/c/src/p0002.c +++ b/c/src/p0002.c @@ -17,6 +17,7 @@ four million, find the sum of the even-valued terms. #ifndef EULER_P0002 #define EULER_P0002 #include +#include #include #include "include/fibonacci.h" @@ -33,7 +34,7 @@ uint64_t p0002() { #ifndef UNITY_END int main(int argc, char const *argv[]) { - printf("%lu\n", p0002()); + printf("%" PRIu64 "\n", p0002()); return 0; } #endif diff --git a/c/src/p0003.c b/c/src/p0003.c index 402bfb36..c154004a 100644 --- a/c/src/p0003.c +++ b/c/src/p0003.c @@ -13,6 +13,7 @@ What is the largest prime factor of the number 600851475143 ? #ifndef EULER_P0003 #define EULER_P0003 #include +#include #include #include "include/primes.h" @@ -27,7 +28,7 @@ uint64_t p0003() { #ifndef UNITY_END int main(int argc, char const *argv[]) { - printf("%lu\n", p0003()); + printf("%" PRIu64 "\n", p0003()); return 0; } #endif diff --git a/c/src/p0004.c b/c/src/p0004.c index e1393162..9acb6fd5 100644 --- a/c/src/p0004.c +++ b/c/src/p0004.c @@ -13,6 +13,7 @@ Find the largest palindrome made from the product of two 3-digit numbers. #ifndef EULER_P0004 #define EULER_P0004 #include +#include #include #include "include/digits.h" @@ -41,7 +42,7 @@ uint32_t p0004() { #ifndef UNITY_END int main(int argc, char const *argv[]) { - printf("%u", p0004()); + printf("%" PRIu32 "\n", p0004()); return 0; } #endif diff --git a/c/src/p0005.c b/c/src/p0005.c index db23c3cf..60081abc 100644 --- a/c/src/p0005.c +++ b/c/src/p0005.c @@ -14,6 +14,7 @@ What is the smallest positive number that is evenly divisible by all of the numb #ifndef EULER_P0005 #define EULER_P0005 #include +#include #include #include "include/macros.h" #include "include/primes.h" @@ -40,7 +41,7 @@ uint64_t p0005() { #ifndef UNITY_END int main(int argc, char const *argv[]) { - printf("%lu", p0005()); + printf("%" PRIu64 "\n", p0005()); return 0; } #endif diff --git a/c/src/p0006.c b/c/src/p0006.c index e70550da..0be7be89 100644 --- a/c/src/p0006.c +++ b/c/src/p0006.c @@ -22,6 +22,7 @@ natural numbers and the square of the sum. #ifndef EULER_P0006 #define EULER_P0006 #include +#include #include uint64_t p0006() { @@ -33,7 +34,7 @@ uint64_t p0006() { #ifndef UNITY_END int main(int argc, char const *argv[]) { - printf("%lu", p0006()); + printf("%" PRIu64 "\n", p0006()); return 0; } #endif diff --git a/c/src/p0007.c b/c/src/p0007.c index ac6267b9..eedeb742 100644 --- a/c/src/p0007.c +++ b/c/src/p0007.c @@ -12,6 +12,7 @@ What is the 10 001st prime number? #ifndef EULER_P0007 #define EULER_P0007 #include +#include #include #include "include/primes.h" @@ -29,7 +30,7 @@ uint64_t p0007() { #ifndef UNITY_END int main(int argc, char const *argv[]) { - printf("%lu", p0007()); + printf("%" PRIu64 "\n", p0007()); return 0; } #endif diff --git a/c/src/p0008.c b/c/src/p0008.c index 6e8dc716..7bf69533 100644 --- a/c/src/p0008.c +++ b/c/src/p0008.c @@ -33,6 +33,7 @@ Find the thirteen adjacent digits in the 1000-digit number that have the greates #ifndef EULER_P0008 #define EULER_P0008 #include +#include #include #include "include/macros.h" @@ -73,7 +74,7 @@ uint64_t p0008() { #ifndef UNITY_END int main(int argc, char const *argv[]) { - printf("%lu", p0008()); + printf("%" PRIu64 "\n", p0008()); return 0; } #endif diff --git a/c/src/p0009.c b/c/src/p0009.c index aa2bd172..2dd11351 100644 --- a/c/src/p0009.c +++ b/c/src/p0009.c @@ -16,6 +16,7 @@ Find the product abc. #ifndef EULER_P0009 #define EULER_P0009 #include +#include #include uint64_t p0009() { @@ -34,7 +35,7 @@ uint64_t p0009() { #ifndef UNITY_END int main(int argc, char const *argv[]) { - printf("%lu", p0009()); + printf("%" PRIu64 "\n", p0009()); return 0; } #endif diff --git a/c/src/p0010.c b/c/src/p0010.c index 9270b186..2f30c46e 100644 --- a/c/src/p0010.c +++ b/c/src/p0010.c @@ -12,6 +12,7 @@ Find the sum of all the primes below two million. #ifndef EULER_P0010 #define EULER_P0010 #include +#include #include #include "include/primes.h" @@ -26,7 +27,7 @@ uint64_t p0010() { #ifndef UNITY_END int main(int argc, char const *argv[]) { - printf("%lu", p0010()); + printf("%" PRIu64 "\n", p0010()); return 0; } #endif diff --git a/c/src/p0011.c b/c/src/p0011.c index 24f504a5..44b78db5 100644 --- a/c/src/p0011.c +++ b/c/src/p0011.c @@ -34,6 +34,7 @@ the 20×20 grid? #ifndef EULER_P0011 #define EULER_P0011 #include +#include #include #include "include/macros.h" @@ -88,7 +89,7 @@ uint64_t p0011() { #ifndef UNITY_END int main(int argc, char const *argv[]) { - printf("%lu", p0011()); + printf("%" PRIu64 "\n", p0011()); return 0; } #endif diff --git a/c/src/p0012.c b/c/src/p0012.c index d6bcf1a5..214c628d 100644 --- a/c/src/p0012.c +++ b/c/src/p0012.c @@ -29,6 +29,7 @@ divisors? #ifndef EULER_P0012 #define EULER_P0012 #include +#include #include #include "include/factors.h" @@ -54,7 +55,7 @@ uint64_t p0012() { #ifndef UNITY_END int main(int argc, char const *argv[]) { - printf("%lu", p0012()); + printf("%" PRIu64 "\n", p0012()); return 0; } #endif diff --git a/c/src/p0013.c b/c/src/p0013.c index badfa361..a3454ad6 100644 --- a/c/src/p0013.c +++ b/c/src/p0013.c @@ -111,6 +111,7 @@ Work out the first ten digits of the sum of the following one-hundred 50-digit n #ifndef EULER_P0013 #define EULER_P0013 #include +#include #include #include "include/bcd.h" @@ -237,7 +238,7 @@ uint64_t p0013() { #ifndef UNITY_END int main(int argc, char const *argv[]) { - printf("%lu\n", p0013()); + printf("%" PRIu64 "\n", p0013()); return 0; } #endif diff --git a/c/src/p0014.c b/c/src/p0014.c index cd85df17..e37b3930 100644 --- a/c/src/p0014.c +++ b/c/src/p0014.c @@ -23,6 +23,7 @@ NOTE: Once the chain starts the terms are allowed to go above one million. #ifndef EULER_P0014 #define EULER_P0014 #include +#include #include #include "include/macros.h" @@ -58,7 +59,7 @@ uint64_t p0014() { #ifndef UNITY_END int main(int argc, char const *argv[]) { - printf("%lu", p0014()); + printf("%" PRIu64 "\n", p0014()); return 0; } #endif diff --git a/c/src/p0015.c b/c/src/p0015.c index 63afe0b1..de9d3ac0 100644 --- a/c/src/p0015.c +++ b/c/src/p0015.c @@ -17,6 +17,7 @@ How many such routes are there through a 20×20 grid? #ifndef EULER_P0015 #define EULER_P0015 #include +#include #include #include "include/math.h" @@ -28,7 +29,7 @@ uint64_t p0015() { #ifndef UNITY_END int main(int argc, char const *argv[]) { - printf("%lu", p0015()); + printf("%" PRIu64 "\n", p0015()); return 0; } #endif diff --git a/c/src/p0016.c b/c/src/p0016.c index 762f5143..abab7dc7 100644 --- a/c/src/p0016.c +++ b/c/src/p0016.c @@ -13,6 +13,7 @@ What is the sum of the digits of the number 21000? #ifndef EULER_P0016 #define EULER_P0016 #include +#include #include #include "include/bcd.h" @@ -28,7 +29,7 @@ uint64_t p0016() { #ifndef UNITY_END int main(int argc, char const *argv[]) { - printf("%lu\n", p0016()); + printf("%" PRIu64 "\n", p0016()); return 0; } #endif diff --git a/c/src/p0017.c b/c/src/p0017.c index ba9e72f3..8018cfd1 100644 --- a/c/src/p0017.c +++ b/c/src/p0017.c @@ -19,6 +19,7 @@ British usage. #ifndef EULER_P0017 #define EULER_P0017 #include +#include #include uint32_t to_string_len(uint64_t n); @@ -89,7 +90,7 @@ uint64_t p0017() { #ifndef UNITY_END int main(int argc, char const *argv[]) { - printf("%lu\n", p0017()); + printf("%" PRIu64 "\n", p0017()); return 0; } #endif diff --git a/c/src/p0020.c b/c/src/p0020.c index ed5defb0..53d564ac 100644 --- a/c/src/p0020.c +++ b/c/src/p0020.c @@ -13,6 +13,7 @@ Find the sum of the digits in the number 100! #ifndef EULER_P0020 #define EULER_P0020 #include +#include #include uint64_t p0020() { @@ -41,7 +42,7 @@ uint64_t p0020() { #ifndef UNITY_END int main(int argc, char const *argv[]) { - printf("%lu\n", p0020()); + printf("%" PRIu64 "\n", p0020()); return 0; } #endif diff --git a/c/src/p0022.c b/c/src/p0022.c index 315035fd..71b4a682 100644 --- a/c/src/p0022.c +++ b/c/src/p0022.c @@ -15,6 +15,7 @@ Find the sum of all the multiples of 3 or 5 below 1000. #ifndef EULER_P0022 #define EULER_P0022 #include +#include #include #include "include/macros.h" #include "include/utils.h" @@ -52,7 +53,7 @@ uint64_t p0022() { #ifndef UNITY_END int main(int argc, char const *argv[]) { - printf("%lu\n", p0022()); + printf("%" PRIu64 "\n", p0022()); return 0; } #endif diff --git a/c/src/p0025.c b/c/src/p0025.c index 3b91e3c5..42f270bf 100644 --- a/c/src/p0025.c +++ b/c/src/p0025.c @@ -29,6 +29,7 @@ What is the index of the first term in the Fibonacci sequence to contain 1000 di #ifndef EULER_P0025 #define EULER_P0025 #include +#include #include #include "include/bcd.h" @@ -47,7 +48,7 @@ uint64_t p0025() { #ifndef UNITY_END int main(int argc, char const *argv[]) { - printf("%lu\n", p0025()); + printf("%" PRIu64 "\n", p0025()); return 0; } #endif diff --git a/c/src/p0030.c b/c/src/p0030.c index 50a13583..f600f079 100644 --- a/c/src/p0030.c +++ b/c/src/p0030.c @@ -18,6 +18,7 @@ Find the sum of all the numbers that can be written as the sum of fifth powers o #ifndef EULER_P0030 #define EULER_P0030 #include +#include #include #include "include/digits.h" @@ -39,7 +40,7 @@ uint64_t p0030() { #ifndef UNITY_END int main(int argc, char const *argv[]) { - printf("%lu\n", p0030()); + printf("%" PRIu64 "\n", p0030()); return 0; } #endif diff --git a/c/src/p0034.c b/c/src/p0034.c index a139668c..1c9e4bf6 100644 --- a/c/src/p0034.c +++ b/c/src/p0034.c @@ -13,6 +13,7 @@ Note: as 1! = 1 and 2! = 2 are not sums they are not included. #ifndef EULER_P0034 #define EULER_P0034 #include +#include #include #include "include/digits.h" #include "include/math.h" @@ -34,7 +35,7 @@ uint64_t p0034() { #ifndef UNITY_END int main(int argc, char const *argv[]) { - printf("%lu", p0034()); + printf("%" PRIu64 "\n", p0034()); return 0; } #endif diff --git a/c/src/p0076.c b/c/src/p0076.c index 48420fa7..5692173a 100644 --- a/c/src/p0076.c +++ b/c/src/p0076.c @@ -41,6 +41,7 @@ positive integers? #ifndef EULER_P0076 #define EULER_P0076 #include +#include #include #include "include/macros.h" @@ -72,7 +73,7 @@ uint32_t p0076() { #ifndef UNITY_END int main(int argc, char const *argv[]) { - printf("%u", p0076()); + printf("%" PRIu32 "\n", p0076()); return 0; } #endif diff --git a/c/src/p0836.c b/c/src/p0836.c index 11600cb4..bde420c8 100644 --- a/c/src/p0836.c +++ b/c/src/p0836.c @@ -17,6 +17,7 @@ Find f(20230401, 57). Give as your answer the concatenation of the first letters #ifndef EULER_P0836 #define EULER_P0836 #include +#include #include char *p0836() { diff --git a/cplusplus/src/include/math.h b/cplusplus/src/include/math.h index 8deb2ac7..d660f657 100644 --- a/cplusplus/src/include/math.h +++ b/cplusplus/src/include/math.h @@ -5,6 +5,7 @@ #include #include #include +#include using namespace std; diff --git a/cplusplus/src/include/utils.h b/cplusplus/src/include/utils.h index fdf24fac..e08e119f 100644 --- a/cplusplus/src/include/utils.h +++ b/cplusplus/src/include/utils.h @@ -1,6 +1,7 @@ #pragma once #include #include +#include #include #ifdef _WIN32 #include @@ -90,7 +91,7 @@ std::string get_data_file(const char *name) { const size_t ret_code = fread(buffer, 1, length, file); if (ret_code != length) { if (feof(file)) - printf("Error reading %s: unexpected end of file, read %lu of %lu bytes expected\n", name, (uint64_t)ret_code, (uint64_t)length); + printf("Error reading %s: unexpected end of file, read %"PRIu64" of %"PRIu64" bytes expected\n", name, (uint64_t)ret_code, (uint64_t)length); else if (ferror(file)) perror("Error reading data file"); }