From 4b034ce5e34c5472365bcdfc7c590b0e22ae70ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20A=2E=20Ortega?= Date: Wed, 14 Dec 2016 19:34:50 +0100 Subject: [PATCH] Print more info about the file writing. --- src/main.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main.c b/src/main.c index a485c6e..cd52d50 100644 --- a/src/main.c +++ b/src/main.c @@ -130,23 +130,28 @@ nextPrime: mpz_clear(num); if(file != NULL) { - FILE *outFile = fopen(file, "w"); + FILE *outFile = fopen(file, "w+"); if(outFile == NULL) { fprintf(stderr, "Failed create file `%s'.\n", file); goto releaseMemory; } printf("Writing primes to `%s'...\n", file); + puts("0%"); for(size_t i = 0; i < primes.end; ++i) { if(mpz_out_str(outFile, base, primes.list[i]) == 0) { fprintf(stderr, "Error occurred while writing to file `%s'.\n", file); goto releaseMemory; } fprintf(outFile, "\n"); + if(i == primes.end / 4) puts("25%"); + else if(i == primes.end / 2) puts("50%"); + else if(i == primes.end * 3 / 4) puts("75%"); } if(fclose(outFile) != 0) { fprintf(stderr, "Failed to close file `%s'.\n", file); goto releaseMemory; } + puts("100%"); puts("Finished writing primes."); }