All pastes #428415 Raw Edit

Something

public text v1 · immutable
·published 2007-04-07 15:33 UTC
rendered paste body
#include <stdio.h>
#define ZERO 48
#define NINE 57
#define TRUE 1
#define FALSE 0
#define SPACE 32
#define TAB 11
#define ENTER 10

int main() {
      int c = 0;
      int count = 0;
      int i=0;
      int dicerolls[5];
      int precedingWhitespace = TRUE; //First char need no whitespace;
      int incorrectinput=0;
      int valuerange=0;
      int numbervalues=0;
      int whitespace=0;
//    int dicemenu=0; // for the dice menu

      printf("Please enter dice values:\n> ");
      while((c = getchar()) != EOF)
      {          
          if(!((c >= ZERO && c <= NINE) || c==SPACE || c==ENTER)){
          //      printf("Incorrect Input Format: %d\n", c);
                incorrectinput=1;
          }
             
          if (c==SPACE){
            whitespace++;
          }
          if(c >= ZERO && c <= NINE){
              c = c - 48;
              if(!(c >= 1 && c <= 6))
              {
//                  printf("Value out of Range.\n");
                  valuerange=1;

              }
              dicerolls[count] = c;
              count++;
              precedingWhitespace = FALSE;
//              if(count != 5){
//                  printf("Incorrect Number of Values.\n");
//                  numbervalues=1;
//              }
              if(c == SPACE || c == TAB)
              {
                  if(precedingWhitespace == FALSE)
                  {
                      precedingWhitespace = TRUE;
                  }
              }

          }

          i++;


      }
      if (count!=5){
      numbervalues=1;
      }
   
      if (whitespace!=4){
        incorrectinput=1;
      }  
    
      if (incorrectinput==1){
         printf("\nIncorrect Input Format.\n");
         valuerange=0;
         numbervalues=0;
      }
      if (valuerange==1){
         printf("\nValue out of Range.\n");
         numbervalues=0;
      }
      if (numbervalues==1){
         printf("\nIncorrect Number of Values.\n");
      }
i=0;
while (i < count){
printf("Your dice values are: %d\n", dicerolls[i]);
i++;
}



/*
printf("Please choose:\n 1 - > Reroll some dice \n 2 - > Reroll all dice\n 3 - > Keep dice\n");
scanf("%d",&dicemenu);
printf("You chose: %d",dicemenu);
*/


return(0);
}