answersLogoWhite

0


Best Answer

There is no need to assume the length if the sentence is represented by a null-terminated string. The following function will strip out all the vowels in any null-terminated string of any length, returning the number of vowels removed. Note that we don't create a new string, we simply modify the existing one since we know the modified string cannot be any longer than the existing one. If you want to retain the original string, simply make a copy of it before invoking this function.

The p variable is a pointer and will initially refer to the first character of str, which is also a pointer. The cnt variable maintains a count of the vowels we removed. We use the str pointer to advance through the string one character at a time. When str is referring to a vowel we simply advance str to the next character leaving p where it is (effectively ignoring the vowels) and increment cnt. When str refers to a non-vowel, we copy the character from str to p and advance both pointers. When str reaches the null-terminator, we place a null-terminator in p and return the value of cnt.

If any vowels were found there will be cnt characters beyond the new null-terminator. If the original string was a fixed-length array then you cannot remove these extra characters, but for variable length strings you may wish to reallocate, reducing the size of the allocation by cnt characters.

int strip_vowels (char* str)

{ char * p = str;

int cnt = 0;

if (str==NULL) return cnt;

while (*str != '\0') // test for null-terminator

{

switch (*str) // test for vowels

{

case 'a': case 'A':

case 'e': case 'E':

case 'i': case 'I':

case 'o': case 'O':

case 'u': case 'U':

str++; // str refers to a vowel, so ignore and advance to next character

cnt++; // increment the count

break;

default:

*p++ = *str++; // non-vowel -- copy the character and advance both pointers

break;

}

}

*p = '\0'; // ensure the modified string is null-terminated!

return cnt;

}

User Avatar

Wiki User

7y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How do you write a program to delete all the vowels from a sentence assuming the sentence is no more than 80 characters long?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Is there any cheats in World of Warcraft r?

Sure just delete your characters, and then remove the program via the Control Panel "Add/Remove Programs"


A program to make fake World of Warcraft characters?

yes you can delete pck. files but this ca result in a failure of the game's mechanics and therefore the game.


How can you Delete characters in Mario Kart 7?

You can't, characters are permanent.


How can you delete a program that wont delete?

One should not delete a program,programs can never be deleted they should always be uninstalled.Deleting a program can never help because if you delete a program u will not see it there but it is used by the computer or system.When you uninstall a program it is totally removed from the computer and is never used again unless u install it.


To delete selected characters press the delete key or the?

Back Space key.


How do you delete a Regnum account?

You can't fully delete it. However. you can delete all characters created on that account and be inactive.


What are two ways to delete characters?

backspace


How do you delete an adventure quest account?

you cant delete the account you can delete the characters though login then press the character you want to delete then a button says delete press that button


What is a descriptive sentence for the word delete?

Did You Delete the files off of the computer ?


How do you delete custom characters in Lego batman 2?

you must first get 100% completion on the game before being able to delete/add custom characters.


What are the two keys of the key board that delete the character?

Backspace deletes the characters to the left of the cursor while delete deletes the characters to the right. (The cursor is the vertical line that flashes on and off where you are typing text)


How do delete books from the sony app on the computer?

go into the program files and delete system 32