Print more info about the file writing.

This commit is contained in:
Nicolás A. Ortega 2016-12-14 19:34:50 +01:00
parent f146dbf11c
commit 4b034ce5e3
No known key found for this signature in database
GPG Key ID: 614272579C2070D1

View File

@ -130,23 +130,28 @@ nextPrime:
mpz_clear(num); mpz_clear(num);
if(file != NULL) { if(file != NULL) {
FILE *outFile = fopen(file, "w"); FILE *outFile = fopen(file, "w+");
if(outFile == NULL) { if(outFile == NULL) {
fprintf(stderr, "Failed create file `%s'.\n", file); fprintf(stderr, "Failed create file `%s'.\n", file);
goto releaseMemory; goto releaseMemory;
} }
printf("Writing primes to `%s'...\n", file); printf("Writing primes to `%s'...\n", file);
puts("0%");
for(size_t i = 0; i < primes.end; ++i) { for(size_t i = 0; i < primes.end; ++i) {
if(mpz_out_str(outFile, base, primes.list[i]) == 0) { if(mpz_out_str(outFile, base, primes.list[i]) == 0) {
fprintf(stderr, "Error occurred while writing to file `%s'.\n", file); fprintf(stderr, "Error occurred while writing to file `%s'.\n", file);
goto releaseMemory; goto releaseMemory;
} }
fprintf(outFile, "\n"); 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) { if(fclose(outFile) != 0) {
fprintf(stderr, "Failed to close file `%s'.\n", file); fprintf(stderr, "Failed to close file `%s'.\n", file);
goto releaseMemory; goto releaseMemory;
} }
puts("100%");
puts("Finished writing primes."); puts("Finished writing primes.");
} }