Tuesday, July 14, 2009

Leaving out a vowels in C++ file?

Can anybody help me??? What i need to do is to leave out the vowels in ac++ file.

Leaving out a vowels in C++ file?
Interesting question... I assume you want to parse C++, and remove the vowels on user identifiers (eg. "shrouding" the source itself).





Is this what you are after? Or do you simply want a filter to remove vowels from anything...





If the second is what you want, try something like (note, no real C++ features used, aren't needed)





#include %26lt;strings.h%26gt;


#include %26lt;stdio.h%26gt;





int main()


{


int c;


while ((c = getchar()) != EOF) {


if (index("aeiouAEIOU", c)) {


putchar(c);


}


}


return 0;


}





would do it. If you want to shroud C++ source, the project is a bit (understatement) bigger -- start with a BNF description of C++, and look at SNOBOL4 (www.snobol4.org). SNOBOL4 will accept the BNF description (more or less) directly, and will let you modify the user variables (function names, etc.) as they are seen. My estimate -- it will take 1 to 2 months to write the thing. Alternatively, look for "C++ source shroud" on google -- that gave my www.abxsoft.com as a possible source for this program.
Reply:just write a function








void no_vowels(std::string%26amp; full_string){





std::string result;





for(std::string::iterator back = full_string.rbegin();back != full_string.begin(); --back){





if(*front != "A" || *front != "a" || *front != "E" ...ect){





result += *back;





};











full_string = %26amp;result;


};











that will do it for strings....i think....its the gist of it i think you need to start at the back of the string, and cuz _ += will add it to the front....i could be wrong, assuming u know file IO that shouldn't be too bad....u can make it return a string pretty easily too
Reply:I don't understand...can you explain
Reply:What is a C++ file?





I suspect you are supposed to write C++ code remove all the vowels from some text, then output the remaining characters it to a file. Correct?





You will need to look at every character in the text, determine if it is a vowel, then decide whether you will write it or skip it. Try writing a function bool IsVowel(char c ), then write code that determines if 'c' is a vowel. Don't forget that vowels can be upper or lower case. Think about using a switch statement here.

peony

No comments:

Post a Comment