w3resource

C Programming: Convert vowels into upper case character in a given string

C String: Exercise-34 with Solution

Write a C programming to convert vowels into upper case character in a given string.

Sample Solution:

C Code:

#include 
int main()
{
    char string1[255];
    int  i;
   printf("Input a sentence: ");
   gets(string1);
   printf("The original string:\n");
   puts(string1);
   i=0;
    while(string1[i]!='\0')
    {
        if(string1[i]=='a' ||string1[i]=='e' ||string1[i]=='i' ||string1[i]=='o' ||string1[i]=='u')
            string1[i]=string1[i]-32;
        i++;
    }
    printf("After converting vowels into upper case the sentence becomes:\n");
    puts(string1);
}

Sample Output:

 Input a sentence: The original string:
w3resource
After converting vowels into upper case the sentence becomes:
w3rEsOUrcE 

Flowchart :

Flowchart: Convert vowels into upper case character in a given string

C Programming Code Editor:

Improve this sample solution and post your code through Disqus.

Previous: Write a C programming to count of each character in a given string.
Next: C Date Time Exercises Home

What is the difficulty level of this exercise?



C Programming: Tips of the Day

Is there a way to specify how many characters of a string to print out using printf()?

The basic way is:

printf ("Here are the first 8 chars: %.8s\n", "A string that is more than 8 chars"); 

The other, often more useful, way is:

printf ("Here are the first %d chars: %.*s\n", 8, 8, "A string that is more than 8 chars"); 

Here, you specify the length as an int argument to printf(), which treats the '*' in the format as a request to get the length from an argument.

You can also use the notation:

printf ("Here are the first 8 chars: %*.*s\n",
        8, 8, "A string that is more than 8 chars"); 

This is also analogous to the "%8.8s" notation, but again allows you to specify the minimum and maximum lengths at runtime - more realistically in a scenario like:

printf("Data: %*.*s Other info: %d\n", minlen, maxlen, string, info); 

The POSIX specification for printf() defines these mechanisms.

Ref: https://bit.ly/395Zj2j