Computing.Net > Forums > Programming > removing letters in a string

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Click here to start participating now! Also, check out the New User Guide.

removing letters in a string

Reply to Message Icon

Name: zerolink
Date: March 11, 2004 at 05:28:18 Pacific
OS: Windows XP home
CPU/Ram: 1.4 ghz/1 gig ram
Comment:

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



Sponsored Link
Ads by Google

Response Number 1
Name: zerolink
Date: March 11, 2004 at 05:54:40 Pacific
Reply:

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


0

Response Number 2
Name: wizard-fred
Date: March 11, 2004 at 06:35:07 Pacific
Reply:

When you remove the vowel, don't replace but concatenate the front and back parts


0

Response Number 3
Name: Ronin1
Date: March 11, 2004 at 16:41:35 Pacific
Reply:

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


0

Response Number 4
Name: zerolink
Date: March 13, 2004 at 07:24:45 Pacific
Reply:

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


0

Response Number 5
Name: wizard-fred
Date: March 13, 2004 at 08:52:29 Pacific
Reply:

I don't do C.

Here's a solution in PowerBASIC compiler (QBASIC)

----------------
rem delvowel.bas 2004-03-13 wizard-fred

aa$ = 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 ...


0

Related Posts

See More



Sponsored Link
Ads by Google
Reply to Message Icon

Validate partial xml by s... linking 2 different rdms



Post Locked

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


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: removing letters in a string

trimming spaces in a string www.computing.net/answers/programming/trimming-spaces-in-a-string/1025.html

asp sql - sql query for last char in a string www.computing.net/answers/programming/asp-sql-sql-query-for-last-char-in-a-string/18767.html

Adding tabs in a string in vb.net www.computing.net/answers/programming/adding-tabs-in-a-string-in-vbnet/11853.html