Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hello
i am trying to make a simple function that takes an input string and scans through it removing all the vowels. is there a simple approch to this problem?thank you for all the help
Zero

update----
i was able to make a function to remove the vowels in a string.. however, the way i have the function set up it puts a space where a vowel was. is there a way to delet the spaces in the string? for example i put "amanda" in the function and get
" m n d " is there a way to make it "mnd" ?thank you for all the help
i appriciate it!Zero

Hmm... let's try something risky for grins.
#include <stdio.h>
#include <string.h>
#include <stdlib.h>void purge(char *str)
{
int i=0, j=0;
char *sptr = malloc(strlen(str) + 1);while(*(str + i) != '\0')
{
if(tolower(*(str + i)) != 'a' &&
tolower(*(str + i)) != 'e' &&
tolower(*(str + i)) != 'i' &&
tolower(*(str + i)) != 'o' &&
tolower(*(str + i)) != 'u')
sptr[j++] = *(str + i);i++;
}sptr[j] = '\0';
strcpy(str, sptr);
free(sptr);
}int main()
{
char arr[] = "Amanda";puts(arr);
purge(arr);
puts(arr);while(getchar() != '\n');
return 0;
}Oops... sorry, you stated that you needed a simple function. :P

Thank you all for the help! I still seem to come up with problems and not sure on how to solve them.
here is what i have:#include <stdio.h>
#include <string.h>
#include <ctype.h>void erasevowels(char *inputstring, char *newstring);
int main(void)
{
char inputstring[22] = "amanda";
char newstring[22] = " ";erasevowels(inputstring, newstring);
printf("%d\n\n\n", strlen(inputstring));
printf("%s\n\n", newstring);
return 0;}
void erasevowels(char *inputstring, char *newstring)
{
int i, j, temp;temp = strlen(inputstring);
i = 0;
for(j=0; j < temp; j++)
{
for(i=0; i<temp; i++)
{
if(inputstring[i] == 'a' || inputstring[i] == 'e' || inputstring[i] == 'i' || inputstring[i] == 'o' || inputstring[i] == 'u')
{
newstring[i] = inputstring[i+1];
inputstring[i+1] = ' ';
}
else
{
newstring[i] = inputstring[i];
}
}
}
}
sorry bout the spacing..some times i have the function remove all the vowels but others it does not. not sure why but i think it has to do with my looping. im also still have problems with the space character.
Any help you can provide i appriciate it
Thank you all.Zero

I don't do C.
Here's a solution in PowerBASIC compiler (QBASIC)
----------------
rem delvowel.bas 2004-03-13 wizard-fredaa$ = command$
if (aa$ = "") then print "Useage: DELVOWEL input_string" : end
bb$ = ""
for cc% = 1 to len(aa$)
dd$ = mid$(aa$, cc%, 1)
if (instr(1, "AEIOU", ucase$(dd$)) = 0) then bb$ = bb$ + dd$
next cc%
print "Vowels removed - from ->"; aa$; "<- to ->"; bb$; "<-"
---------------Program Lines are double spaced, Single spaced lines are continued.
BASIC is ...

![]() |
Validate partial xml by s...
|
linking 2 different rdms
|

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |