Discarding the vowels in a string using 'continue' keyword for C programming

 

 

Compiler: Visual C++ Express Edition 2005

Compiled on Platform: Windows XP Pro SP2

Header file: Standard

Additional library: none/default

Additional project setting: Set project to be compiled as C

Project -> your_project_name Properties -> Configuration Properties -> C/C++ -> Advanced -> Compiled As: Compiled as C Code (/TC)

Other info: none

To do: Discarding the vowels in a string using 'continue' keyword for C programming

To show: How to use the continue C keyword to skip some vowels in the given string

 

// Example of the 'continue' keyword, discarding the vowels in a string

#include <stdio.h>

 

void main(void)

{

// declare storage for input, an array and counter variable

char buffer[81];

int ctr;

 

// input and read a line of text using puts() and gets() which are predefined functions in stdio.h

// secure versions are puts_s() and gets_s()

puts("Enter a line of text and press Enter key,");

puts("all the vowels will be discarded!:\n");

gets_s(buffer, 81);

 

//go through the string, displaying only those characters that are not lowercase vowels

for(ctr=0; buffer[ctr] != '\0'; ctr++)

{

// If the character is a lowercase vowel, loop back without displaying it

if((buffer[ctr]=='a')||(buffer[ctr]=='e')||(buffer[ctr]=='i')||(buffer[ctr]=='o')||(buffer[ctr]=='u'))

continue;

// If not a vowel, display it

putchar(buffer[ctr]);

}

printf("\n");

}

 

Output example:

 

Enter a line of text and press Enter key,

all the vowels will be discarded!:

Let have some fun playing with C codes

Lt hv sm fn plyng wth C cds

Press any key to continue . . .

 

 

C and C++ Programming Resources | C & C++ Code Example Index