/*
In this task, you should write a program that analyses sentences provided by the user. In the first step, you have to implement the user input in the main using fgets (see TODO in the main function). You can assume that the user will never enter more than 200 characters. Then, you should implement two functions:

    countVowel(char string[]): This function counts the vowels (de: Vokale) in the string and returns it as an integer. The return value (number of vowels) is then printed in the provided main() function.
    printReverse(char string[]): This function prints the provided string in reverse and adds a \n at the end. It has no return value (void). Make sure to avoid printing the string’s null terminator. If the string is empty (no characters, just the user pressing ‘Enter’/’Return’) the function should print Empty string\n and end.

You are allowed to use any library, including <string.h>.

This is an example (once the code is fixed): 

Enter sentence (max 200 chars): Hello Students
number of vowels: 4

stnedutS olleH
*/

#include <stdio.h>
#include <string.h>

// TODO: write your functions
int countVowel(char* string);
void printReverse(char* string);

int main(void)
{
  char my_string[200] = {0};
  printf("Enter sentence (max 200 chars): ");
  fgets(my_string,200,stdin);
  
  int nr_vowel = countVowel(my_string);
  printf("number of vowels: %d\n", nr_vowel);
  printReverse(my_string);
  
  return 0;
}

int countVowel(char* string)
{
  int position = 0;
  int vowels = 0;

  while (string[position] != '\0')
  {
    if (
      string[position] == 'a' ||
      string[position] == 'e' ||
      string[position] == 'i' ||
      string[position] == 'o' ||
      string[position] == 'u' ||
      string[position] == 'A' ||
      string[position] == 'E' ||
      string[position] == 'I' ||
      string[position] == 'O' ||
      string[position] == 'U'
    ) { vowels++; }
    position++;
  }
  return vowels;
}

void printReverse(char* string)
{
  int position = 0;
  while (string[position] != '\n') { position++; }
  if (position == 0) { printf("Empty string\n"); return; }
  while (position >= 0)
  {
    printf("%c",string[position]);
    position--;
  }
  printf("\n");
}
