Thursday 8 August 2013

printf: unknown conversion type character ')' in format -Wformat

printf: unknown conversion type character ')' in format -Wformat

I have written a C program it is giving the following compilation error.
rand_distribution.c:24:7: warning: unknown conversion type character ')'
in format [-Wformat]
at this line
printf("%d: %d (%.2lf %) \n", i+1, frequencies[i],100.0 * frequencies[i]
/ TOTAL_COUNT);
My objective to get an output like this.
1: 333109 (16.66%)
2: 333113 (16.66%)
3: 333181 (16.66%)
4: 333562 (16.68%)
5: 333601 (16.68%)
6: 333434 (16.67%)
That is to say '%' before the ')' should be printed as it is without being
interpreted.How do I achieve this?
#include <stdio.h>
#include <stdlib.h> // for rand(), srand()
#include <time.h> // for time()
const int TOTAL_COUNT = 2000000; // Close to INT_MAX
const int NUM_FACES = 6;
int frequencies[6] = {0}; // frequencies of 0 to 5, init to zero
int main()
{
srand(time(0)); /* seed random number generator with current time*/
/* Throw the die and count the frequencies*/
int i = 0;
for (i = 0; i < TOTAL_COUNT; ++i)
{
++frequencies[rand() % 6];
}
/*Print statisics*/
for (i = 0; i < NUM_FACES; i++)
{
printf("%d: %d (%.2lf %) \n", i+1, frequencies[i],100.0 *
frequencies[i] / TOTAL_COUNT);
}
}

No comments:

Post a Comment