title: Is there something wrong with my gets function? we haven't been though about fgets yet in class. only gets
body: <p>for example when I type in a string "Hello", when I press 'a' it should print "There are 2 vowels." Instead, it says there are 0. I'm new to programming and this is the first language I am learning. Help?</p>
  
  <pre><code>    /*
          Student: Josiah Eleazar T. Regencia
          Course: BSIT 1
          Subject: SCS 101
          Professor: Daniel B. Garcia
  
  
          Problem definition:
              Write a menu program that will count the vowels and consonants in the string
  
  */
  
  #include &lt;stdio.h&gt; //printf and scanf functions
  #include &lt;string.h&gt; //string functions
  #include &lt;stdlib.h&gt;
  #include &lt;conio.h&gt;
  
  #define PROMPT "Type in a word, a phrase, or a sentence." //instucts the user
  
  /*
      Declaring the function for the user's menu
  */
  void menu();
  
  /*
      Declaration of function needed to count the vowels in the string
  */
  int vowel_count(char *stringInput); //declaring the function to count the vowels sounds
  
  /*
      Declaration of function needed to count the consonants in the stringn
  */
  int consonant_count(char *stringInput); //declaring the functions to count the consonant sounds
  
  /*
      Declaring the function needed to convert the streeting to uppercase
  */
  int uppercase(char *stringInput);
  
  /*
      Declaring the function needed to convert the streeting to uppercase
  */
  int lowercase(char *stringInput);
  
  int main () {
  
  
      char userInput[100]; // the string the user inputs
  
      char commandKey[1]; //this key is for the menu
  
      char newInput[100]; //this is for the new input to user will put in
  
      int stringLength; //to identify the length of the string
  
      /*
          Variables for counting the vowels and consonants
      */
  
      int consonantCount;
  
      printf("%s\n\n", PROMPT); //instucts the user
  
      gets(userInput);
  
      stringLength = strlen(userInput); //gets the length of the string
  
      //fgets(userInput, 100, stdin);
  
      /*if(stringLength &gt; 0 &amp;&amp; userInput[stringLength - 1] == '\n') {
  
          userInput[stringLength - 1] ='\0';
      }*/
  
      menu(); //prints out the menu for the user to pick his options
  
      /*
          The loop will run what the user asks the program to run while at the same time also asking
          what the programmer wants next
      */
      while(*commandKey != 'X' || *commandKey != 'x') {
  
          //int commandLength; //length of the command key
  
          printf("Enter your menu selection: ");
  
          gets(commandKey);
  
          /*commandLength = strlen(commandKey);
  
          fgets(commandKey, 100, stdin);
  
          if(commandLength &gt; 0 &amp;&amp; commandKey[commandLength - 1] == '\n') {
  
          commandKey[commandLength - 1] ='\0';
      }*/
  
          if(*commandKey == 'A' || *commandKey == 'a') {
  
              int vowelCount;
  
              vowelCount = vowel_count(userInput);
  
              printf("There are %d vowels.\n\n", vowelCount);
  
          }
  
          if(*commandKey == 'B' || *commandKey == 'b') {
  
              consonantCount = consonant_count(userInput);
  
              printf("There are %d consonants.\n\n", consonantCount);
          }
  
          if(*commandKey == 'C' || *commandKey == 'c') {
  
              /*
                  This condition simply converts the input string to all lowercase letters
              */
  
              lowercase(userInput);
          }
  
          if(*commandKey == 'D' || *commandKey == 'd') {
  
              /*
                  This condition simply converts the input string to all lowercase letters
              */
  
              uppercase(userInput);
          }
  
          if(*commandKey == 'E' || *commandKey == 'e') {
  
              /*
                  Prints the current string
                  if the string was converted in lowercase letters, the outcome would be all lowercase letters
                  if the string was converted in uppercase letters, the outcome would be all uppercase letters
              */
  
              printf("%s\n\n", userInput);
          }
  
          if(*commandKey == 'F' || *commandKey == 'f') {
  
              /*
                  When the user wants to test a new string, this is the condition for the user
                  to automatically ask of it
              */
  
              printf("%s\n", PROMPT);
              gets(newInput);
              strcpy(userInput, newInput);
          }
  
          if(*commandKey == 'M' || *commandKey =='m') {
  
              /*
                  In case the user forgets, this will serve as a reminder of the menu
              */
  
              menu();
          }
  
          if(*commandKey == 'X' || *commandKey == 'x') {
              printf("Goodbye!\n");
              break;
          }
      }
  }
  
  //Function that displays the menu.
  void menu() {
  
      /*
          These are the set of command keys given to the user
      */
      printf("\n\n\n");
      printf("PRESS:\n\n");
      printf("         A - Count the number of vowels in the string.\n");
      printf("         B - Count the number of consonants in the string.\n");
      printf("         C - Convert the string to uppercase.\n");
      printf("         D - Convert the string to lowecase.\n");
      printf("         E - Display the current string.\n");
      printf("         F - Enter another string.\n");
      printf("\n");
      printf("         M - Display this menu.\n");
      printf("         X - Exit the program.\n");
      printf("\n\n");
  }
  
  /*
      Defining the function for the vowel counting
  */
  
  int vowel_count(char *stringInput) {
  
      if ( *stringInput == '\0')
          return 0;
      else
          return vowel_count(stringInput + 1) + (*stringInput == 'a' || *stringInput == 'A')
                                              + (*stringInput == 'e' || *stringInput == 'E')
                                              + (*stringInput == 'i' || *stringInput == 'I')
                                              + (*stringInput == 'o' || *stringInput == 'O')
                                              + (*stringInput == 'u' || *stringInput == 'U');
  }
  
  /*
      Defining the function for the vowel counting
  */
  int consonant_count(char *stringInput) {
  
      if (*stringInput == '\0')
          return 0;
      else
          return consonant_count(stringInput + 1) + (*stringInput == 'b' || *stringInput == 'B')
                                                  + (*stringInput == 'c' || *stringInput == 'C')
                                                  + (*stringInput == 'd' || *stringInput == 'D')
                                                  + (*stringInput == 'f' || *stringInput == 'F')
                                                  + (*stringInput == 'g' || *stringInput == 'G')
                                                  + (*stringInput == 'h' || *stringInput == 'H')
                                                  + (*stringInput == 'j' || *stringInput == 'J')
                                                  + (*stringInput == 'k' || *stringInput == 'K')
                                                  + (*stringInput == 'l' || *stringInput == 'L')
                                                  + (*stringInput == 'm' || *stringInput == 'M')
                                                  + (*stringInput == 'n' || *stringInput == 'N')
                                                  + (*stringInput == 'p' || *stringInput == 'P')
                                                  + (*stringInput == 'q' || *stringInput == 'Q')
                                                  + (*stringInput == 'r' || *stringInput == 'R')
                                                  + (*stringInput == 's' || *stringInput == 'S')
                                                  + (*stringInput == 't' || *stringInput == 'T')
                                                  + (*stringInput == 'v' || *stringInput == 'V')
                                                  + (*stringInput == 'w' || *stringInput == 'W')
                                                  + (*stringInput == 'x' || *stringInput == 'X')
                                                  + (*stringInput == 'y' || *stringInput == 'Y')
                                                  + (*stringInput == 'z' || *stringInput == 'Z');
  }
  
  /*
      Defining the function for the conversion of the string to all uppercase letters
  */
  int uppercase(char *stringInput) {
  
      while(*stringInput) {
  
          *stringInput = toupper(*stringInput);
  
          stringInput++;
      }
  
  }
  
  /*
      Defining the function for the conversion of the string to all uppercase letters
  */
  int lowercase(char *stringInput) {
  
      while(*stringInput) {
  
          *stringInput = tolower(*stringInput);
  
          stringInput++;
      }
  
  }
  </code></pre>