#include #include #include #include const int STRLEN= 50; int main(int argc, char **argv) { char *vowels="aeiou"; char *ptr,*found_vowels,*src,*dest,*instr; // first check that there is at least one argument if(argc < 2) { cout << " there aren't enough arguments" << endl; cout << "Usage: " << argv[0] << " string1 [string2 string 3 ... ]" << endl; exit(1); } /* run this for each of the arguments on the command line. */ for(int argcount = 1; argcount < argc; argcount ++ ) { src= instr=argv[argcount]; /* the string to work on */ cout << "the input string was :" << instr << ":" << endl; // get some new space for the vowels. We know there aren't more // vowels than there are letters in the string found_vowels = new char[strlen(instr) + 1]; dest = found_vowels; while(*instr) { // for each letter in the input string ptr = vowels; // for each vowel, check if this letter is one while (*ptr) { if(*instr == *ptr) { // found one *dest++ = *ptr; } ptr++; // go to the next vowel } // inner while *dest = '\0'; /* we have to put a NUL at the end of the string */ instr++; } // outer while cout << "Done using vowel string method for string " << src << endl; cout << "there were " << strlen(found_vowels) << " vowels and they were " << found_vowels << endl; cout << "\n--------------------------\n" << endl; delete [] found_vowels; // now we do it using a switch statement src= instr=argv[argcount]; /* the string to work on */ found_vowels = new char[strlen(instr) + 1]; dest = found_vowels; while(*instr) { // for each letter in the input string switch(*instr) { case 'a': case 'e': case 'i': case 'o': case 'u': *dest++ = *instr; break; } // esac instr++; } // while *dest = '\0'; cout << "Done using case statement method for string " << src << endl; cout << "there were " << strlen(found_vowels) << " vowels and they were " << found_vowels << endl; cout << "\n--------------------------\n" << endl; delete [] found_vowels; } // for return 0; } // main