Skip to content

Commit 62e9029

Browse files
authored
Format specifier for size_t, calloc check
The correct format specifier for `size_t` is `%zu`. If C89 support is needed, `%lu` along with a cast to `unsigned long` will suffice. Also added error checking for calloc.
1 parent e063abd commit 62e9029

File tree

1 file changed

+5
-1
lines changed
  • project_euler/Problem 07

1 file changed

+5
-1
lines changed

project_euler/Problem 07/sol.c

+5-1
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,16 @@ int main(void) {
99
const unsigned target = 10001;
1010

1111
sieve = calloc(n, sizeof *sieve);
12+
if (!sieve) {
13+
return -1;
14+
}
15+
1216
for (i = 2; i < n; i++) {
1317
if (!sieve[i]) {
1418
size_t j;
1519
count++;
1620
if (count == target) {
17-
printf("%lu\n", i);
21+
printf("%zu\n", i);
1822
break;
1923
}
2024
for (j = i * 2; j < n; j += i) {

0 commit comments

Comments
 (0)