Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
62 lines (43 sloc) 1.09 KB
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "roll.h"
int main(int argc, char **argv)
{
if (argc > 1)
{
clock_t end, start;
double duration;
int digit, i, count = argc - 1, rolls,
*dice = malloc(sizeof(int) * count);
char *get_dice = malloc(sizeof(char) * count),
*new_dice = malloc(sizeof(char) * count);
for (i = 0; i < count; i++)
{
digit = atoi(argv[i + 1]);
if (digit >= 1 && digit <= 6)
get_dice[i] = digit - 1 + '0';
else
{
printf("Error: Invalid Integer\n");
exit(0);
}
}
srand(time(NULL));
start = clock();
for (rolls = 0; strcmp(get_dice, new_dice); rolls++)
for (i = 0; i < count; i++)
new_dice[i] = (rand() % 6) + '0';
end = clock();
duration = (double)(end - start) / CLOCKS_PER_SEC;
for (i = 0; i < count; i++)
dice[i] = get_dice[i] - '0';
roll(count, dice);
printf("\n\n%d rolls in %f seconds (~%d rolls per second)\n\n", rolls,
duration, (int)(rolls / duration + 0.5));
}
else
printf("Usage: roll-again <<integer 1..6>..[integer 1..6]..>\n");
return 0;
}
You can’t perform that action at this time.