How it works...

Again, we will assume that you will not enter a sentence longer than 255 characters. Therefore, we have defined our string array, str , to be of the size 255. When prompted, enter a sentence to assign to the str array. Because a sentence may have blank spaces between the words, instead of scanf, we will use the gets function to accept the sentence.

To access each character of the sentence, we will execute a while loop that will run until the null character is reached in the sentence. After each character of the sentence, it is checked whether it is a lowercase vowel. If it is not a lowercase vowel, the character is ignored and the next character in the sentence is picked up for comparison.

If the character that's accessed is a lowercase vowel, then a value of 32 is subtracted from the ASCII value of the character to convert it to uppercase. Remember that the difference in the ASCII values of lowercase and uppercase letters is 32. That is, the ASCII value of lowercase a is 97 and that of uppercase A is 65. So, if you subtract 32 from 97, which is the ASCII value of lowercase a, the new ASCII value will become 65, which is the ASCII value of uppercase A.

The procedure of converting a lowercase vowel to an uppercase vowel is to first find the vowel in a sentence by using an if statement, and then subtract the value 32 from its ASCII value to convert it to uppercase.

Once all of the characters of the string are accessed and all of the lowercase vowels of the sentence are converted to uppercase, the entire sentence is displayed using the puts function.

Let's use GCC to compile the convertvowels.c program, as follows:

D:\CBook>gcc convertvowels.c -o convertvowels

Let's run the generated executable file, convertvowels.exe, to see the output of the program:

D:\CBook>./convertvowels
Enter a sentence: It is very hot today. Appears as if it might rain. I like rain
The sentence after converting vowels into uppercase is:
It Is vEry hOt tOdAy. AppEArs As If It mIght rAIn. I lIkE rAIn

Voilà! We've successfully converted the lowercase vowels in a sentence to uppercase.