goldbach-conjecture/main.c
Kyle Stevenson 222707a2b9 improved sieve
2025-02-01 14:02:00 +00:00

38 lines
1.1 KiB
C

//
// Created by Kyle Stevenson on 21/01/2025.
//
#include "memory_info.h"
#include "prime_sieves.h"
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h> // For getcwd()
#include <limits.h> // For PATH_MAX
#include <string.h> // For snprintf()
int main() {
// Step 1: Calculate available bits
const size_t availableBits = getAvailableBits(2);
if (availableBits > 0) {
printf("You can allocate ~%zu bits.\n", availableBits);
}
// Step 2: Get absolute path for `primes.db`
char dbFilePath[PATH_MAX];
if (getcwd(dbFilePath, sizeof(dbFilePath)) != NULL) {
if (snprintf(dbFilePath, sizeof(dbFilePath), "%s/primes.db", dbFilePath) >= sizeof(dbFilePath)) {
fprintf(stderr, "Path too long for database file.\n");
return 1;
}
printf("Database file will be created at: %s\n", dbFilePath);
} else {
fprintf(stderr, "Failed to get current working directory.\n");
return 1;
}
// Step 3: Run the Sieve and save primes to SQLite
sieveOfEratosthenes(availableBits, dbFilePath);
return 0;
}