Skip to content

Commit

Permalink
make printf formatting portable
Browse files Browse the repository at this point in the history
  • Loading branch information
LivInTheLookingGlass committed Aug 16, 2024
1 parent c9bbba9 commit 7c9d27c
Show file tree
Hide file tree
Showing 28 changed files with 54 additions and 26 deletions.
3 changes: 2 additions & 1 deletion c/src/include/utils.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#pragma once
#include <inttypes.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
Expand Down Expand Up @@ -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");
}
Expand Down
3 changes: 2 additions & 1 deletion c/src/p0000_template.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ This paragraph should be replaced by the problem description, excluding images.
#ifndef EULER_P0000
#define EULER_P0000
#include <stdint.h>
#include <inttypes.h>
#include <stdio.h>

uint64_t p0000() {
Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion c/src/p0001.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#ifndef EULER_P0001
#define EULER_P0001
#include <stdint.h>
#include <inttypes.h>
#include <stdio.h>
#include "include/iterator.h"

Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion c/src/p0002.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ four million, find the sum of the even-valued terms.
#ifndef EULER_P0002
#define EULER_P0002
#include <stdint.h>
#include <inttypes.h>
#include <stdio.h>
#include "include/fibonacci.h"

Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion c/src/p0003.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ What is the largest prime factor of the number 600851475143 ?
#ifndef EULER_P0003
#define EULER_P0003
#include <stdint.h>
#include <inttypes.h>
#include <stdio.h>
#include "include/primes.h"

Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion c/src/p0004.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Find the largest palindrome made from the product of two 3-digit numbers.
#ifndef EULER_P0004
#define EULER_P0004
#include <stdint.h>
#include <inttypes.h>
#include <stdio.h>
#include "include/digits.h"

Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion c/src/p0005.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 <stdint.h>
#include <inttypes.h>
#include <stdio.h>
#include "include/macros.h"
#include "include/primes.h"
Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion c/src/p0006.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ natural numbers and the square of the sum.
#ifndef EULER_P0006
#define EULER_P0006
#include <stdint.h>
#include <inttypes.h>
#include <stdio.h>

uint64_t p0006() {
Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion c/src/p0007.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ What is the 10 001st prime number?
#ifndef EULER_P0007
#define EULER_P0007
#include <stdint.h>
#include <inttypes.h>
#include <stdio.h>
#include "include/primes.h"

Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion c/src/p0008.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 <stdint.h>
#include <inttypes.h>
#include <stdio.h>
#include "include/macros.h"

Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion c/src/p0009.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Find the product abc.
#ifndef EULER_P0009
#define EULER_P0009
#include <stdint.h>
#include <inttypes.h>
#include <stdio.h>

uint64_t p0009() {
Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion c/src/p0010.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Find the sum of all the primes below two million.
#ifndef EULER_P0010
#define EULER_P0010
#include <stdint.h>
#include <inttypes.h>
#include <stdio.h>
#include "include/primes.h"

Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion c/src/p0011.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ the 20×20 grid?
#ifndef EULER_P0011
#define EULER_P0011
#include <stdint.h>
#include <inttypes.h>
#include <stdio.h>
#include "include/macros.h"

Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion c/src/p0012.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ divisors?
#ifndef EULER_P0012
#define EULER_P0012
#include <stdint.h>
#include <inttypes.h>
#include <stdio.h>
#include "include/factors.h"

Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion c/src/p0013.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 <stdint.h>
#include <inttypes.h>
#include <stdio.h>
#include "include/bcd.h"

Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion c/src/p0014.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 <stdint.h>
#include <inttypes.h>
#include <stdio.h>
#include "include/macros.h"

Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion c/src/p0015.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ How many such routes are there through a 20×20 grid?
#ifndef EULER_P0015
#define EULER_P0015
#include <stdint.h>
#include <inttypes.h>
#include <stdio.h>
#include "include/math.h"

Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion c/src/p0016.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ What is the sum of the digits of the number 21000?
#ifndef EULER_P0016
#define EULER_P0016
#include <stdint.h>
#include <inttypes.h>
#include <stdio.h>
#include "include/bcd.h"

Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion c/src/p0017.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ British usage.
#ifndef EULER_P0017
#define EULER_P0017
#include <stdint.h>
#include <inttypes.h>
#include <stdio.h>

uint32_t to_string_len(uint64_t n);
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion c/src/p0020.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Find the sum of the digits in the number 100!
#ifndef EULER_P0020
#define EULER_P0020
#include <stdint.h>
#include <inttypes.h>
#include <stdio.h>

uint64_t p0020() {
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion c/src/p0022.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Find the sum of all the multiples of 3 or 5 below 1000.
#ifndef EULER_P0022
#define EULER_P0022
#include <stdint.h>
#include <inttypes.h>
#include <stdio.h>
#include "include/macros.h"
#include "include/utils.h"
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion c/src/p0025.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 <stdint.h>
#include <inttypes.h>
#include <stdio.h>
#include "include/bcd.h"

Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion c/src/p0030.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 <stdint.h>
#include <inttypes.h>
#include <stdio.h>
#include "include/digits.h"

Expand All @@ -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
Expand Down
Loading

0 comments on commit 7c9d27c

Please sign in to comment.