Tuesday, July 28, 2009

How do I make a program erase the vowels and the extra spaces in an input w/o using string in c?

As a user inputs a statement like, "How are you?" It will become, "Hw r y?" How is it done? This c is c programming not c++... Thanks!

How do I make a program erase the vowels and the extra spaces in an input w/o using string in c?
Assume the input is in a character array (char myInput[50]) and terminated with a null...





char newin[50];


int x=0, y=0;





for (x=0; x%26lt;strlen(in); x++)


if (in[x]!='a' %26amp;%26amp; in[x]!='e' %26amp;%26amp; in[x]!='i' %26amp;%26amp; in[x]!='o' %26amp;%26amp; in[x]!='u' %26amp;%26amp; in[x]!='A' %26amp;%26amp; in[x]!='B' %26amp;%26amp; in[x]!='I' %26amp;%26amp; in[x]!='O' %26amp;%26amp; in[x]!='U')


newin[y++]=in[a];





newin[y]='\0';








Of course, you could use change the if statement to be more elaborate by checking the ascii value knowing that upper and lowercase chars are offset by a value of 32.
Reply:Why don't you want to use strings? Given that the input is a string, I don't see how this could work.





The code to do this is straightforward, just do a byte by byte copy, skipping any input that you don't like.


No comments:

Post a Comment