Skip to content

Instantly share code, notes, and snippets.

@magamig
Created November 7, 2018 17:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save magamig/ea88d9c83033fc7387ac1577cda158d1 to your computer and use it in GitHub Desktop.
Save magamig/ea88d9c83033fc7387ac1577cda158d1 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main(){
srand(time(NULL));
int c, i, rolls = 0, sides = 0, sum = 0;
FILE *file;
file = fopen("input.txt", "r");
if (file) {
while ((c = getc(file)) != EOF){
if(c != 'd'){
rolls *= 10;
rolls += c-'0';
} else {
while ((c = getc(file)) != '\n'){
sides *= 10;
sides += c-'0';
}
for(i=0; i<rolls; i++){
sum += rand()%sides;
}
printf("%d\n", sum+rolls);
sum = 0;
sides = 0;
rolls = 0;
}
}
fclose(file);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment