Improve error handling

Added error handling in case of memory allocation error for
problems 35, 46, 47, 49 and 50.
This commit is contained in:
daniele 2019-09-22 18:26:36 +02:00
parent 7f64f15e89
commit 846cb06c90
Signed by: fuxino
GPG Key ID: 6FE25B4A3EE16FDA
5 changed files with 25 additions and 5 deletions

View File

@ -18,7 +18,11 @@ int main(int argc, char **argv)
clock_gettime(CLOCK_MONOTONIC, &start);
primes = sieve(N);
if((primes = sieve(N)) == NULL)
{
fprintf(stderr, "Error! Sieve function returned NULL\n");
return 1;
}
for(i = 101; i < 1000000; i += 2)
{

View File

@ -18,7 +18,11 @@ int main(int argc, char **argv)
clock_gettime(CLOCK_MONOTONIC, &start);
primes = sieve(N);
if((primes = sieve(N)) == NULL)
{
fprintf(stderr, "Error! Sieve function returned NULL\n");
return 1;
}
for(i = 3; !found && i < N; i += 2)
{

View File

@ -18,7 +18,11 @@ int main(int argc, char **argv)
clock_gettime(CLOCK_MONOTONIC, &start);
primes = sieve(N);
if((primes = sieve(N)) == NULL)
{
fprintf(stderr, "Error! Sieve function returned NULL\n");
return 1;
}
for(i = 645; !found && i < N - 3; i++)
{

View File

@ -18,7 +18,11 @@ int main(int argc, char **argv)
clock_gettime(CLOCK_MONOTONIC, &start);
primes = sieve(N);
if((primes = sieve(N)) == NULL)
{
fprintf(stderr, "Error! Sieve function returned NULL\n");
return 1;
}
for(i = 1489; i < N && !found; i++)
{

View File

@ -15,7 +15,11 @@ int main(int argc, char **argv)
clock_gettime(CLOCK_MONOTONIC, &start);
primes = sieve(N);
if((primes = sieve(N)) == NULL)
{
fprintf(stderr, "Error! Sieve function returned NULL\n");
return 1;
}
for(i = 2; i < N; i++)
{