Example #1
0
/* This prompts user to enter the number of letters
 * in the word they would like to guess */
int numberOfLetters(){
    
    int number = -1;
    while(1){
        number = -1;
        printf(" \n Please enter the number of letters you would like in the word:");
        do {
            scanf("%d", &number);
            if (number<0) {
                printf("That is not a number.\n");
            }
            flushStdin();
            
        } while (number < 0);
        /*Restrict word length by making sure there is at least one word of that
        * length in the dictionary.*/
        if (!listsAux[number]<=0) {
            printf("You will have  to guess a word %d letters long.\n", number);
            return number;
        }
        else {
            printf("That is not possible. Please pick a number greater than 1  and less than 31.\n");
        }
    }
}
Example #2
0
/*Obtains user guess and verifies that it is valid.
 *Returns the valid character guessed*/
char obtainGuess(){
    /*While incorrect is 1 the function will keep asking
     * the user for input, until a valid guess is entered.*/
    char incorrect=1;
    //While the entered guess is invalid repeat loop
    while (incorrect) {
        printf("Your guess:");
        char letter = getchar();
        flushStdin();
        //verifies that guess is a letter
        if (isalpha(letter)) {
            incorrect=0;
            // Takes care of matching letters of different cases
            char lowerLetter=tolower(letter);
            if (testIfAleadyGuessed(head,letter)) {
                return lowerLetter;
            }
            else {
                printf("This character has already been guessed.\n");
                incorrect = 1;
            }
        } else {
            printf("This character is not a letter. Please input a letter.\n");
        }
    }
}
Example #3
0
unsigned int getSel(void)
{
  unsigned int selection = 0;

  scanf("%u",&selection);
  flushStdin();

  while( !isValid(selection) )
    {
      puts("Selection not valid. Try again :");
      scanf("%u",&selection);
      flushStdin();
    }

  return selection;
}
Example #4
0
File: cli.c Project: htw-ai/algo
int cli_get_student_id()
{
  char stundent_id[10];
  printf("enter student id:\n");
  fgets(stundent_id, sizeof(stundent_id), stdin);
  size_t idLn = strlen(stundent_id) - 1;
  if (stundent_id[idLn] == '\n')
      stundent_id[idLn] = '\0';
  else flushStdin();
  return atoi(stundent_id);
}
Example #5
0
File: io.c Project: eokeeffe/C-code
extern double input()
{
    double user_input=0.0;
    //while scanf gets a correct input
    //clean the buffer and try again
    //scanf is documented to have a return value of
    //the number of inputs it will recieve
    while( scanf("%lf",&user_input) != 1)
    {
        fprintf(stderr,"Please enter a float\r\n");
        flushStdin();
    }
    return user_input;
}
Example #6
0
/* This prompts user to enter the difficulty
 * of the game they would like to play*/
int difficulty(){
    int number = -1;
    while(1){
        number = -1;
        printf(" \n Please enter 1 if you want an easy game, or 0 if you want a difficult game:");
        do {
            scanf("%d", &number);
            //Checks that input was a number
            if (number<0) {
                printf("That is not a number.\n");
            }
            flushStdin();
            
        } while (number<0);
        //Checks that input was in correct range.
        if (number!=0 && number!=1) {
            printf("That is not possible.\n");

        }
        else {
           return number;
        }
    }
}
Example #7
0
/* This prompts user to enter the number of guesses
 * they would like to allow themselves */
int numberOfGuesses(){
    int number = -1;
    while(1){
        number = -1;
        printf(" \n Please enter the number of guesses you would like to allow yourself:");
        do {
            scanf("%d", &number);
            //Checks that input was a number
            if (number<0) {
                printf("That is not a number.\n");
            }
            flushStdin();
            
        } while (number < 0);
        //Checks that input was in correct range.
        if (number<lettersInAlphabet && number>minimumGuesses) {
            printf("You will have %d guesses.\n", number);
            return number;
        }
        else {
            printf("That is not possible. Please pick a number greater than 1  and less than 26.\n");
        }
    }
}