Thread: Replacing vowels in C

  1. #1
    Registered User
    Join Date
    Oct 2007
    Posts
    2

    Replacing vowels in C

    Help! I need to create a program using string functions where you replace a vowel to another vowel.

    ex. Enter your Name: John Boyad

    Your New name is: Jahn Buyid

    How do you make it? I am confused in what commands to use.

  2. #2
    Registered User
    Join Date
    Oct 2007
    Posts
    2
    Quote Originally Posted by modstar89 View Post
    Help! I need to create a program using string functions where you replace a vowel to another vowel.

    ex. Enter your Name: John Boyad

    Your New name is: Jahn Buyid

    How do you make it? I am confused in what commands to use.


    pls. answer his question.. pleeeeaaaaaase...

  3. #3
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    We don't do homework here. As you might have noticed, I have a signature that is appropriate for this and similar occasions.

    If you want us to help with something, or you have detailed questions, ask away and we can try to help.

  4. #4
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    fgets() to read the name, and loop through character-by-character replacing vowels with other vowels.

    Your question is pretty stupid anyway, whats the difference between the "before name" and "new name"? It seems vowels are being replaced with other vowels, but in what way?

  5. #5
    Registered User
    Join Date
    Oct 2007
    Posts
    2
    Quote Originally Posted by zacs7 View Post
    fgets() to read the name, and loop through character-by-character replacing vowels with other vowels.

    Your question is pretty stupid anyway, whats the difference between the "before name" and "new name"? It seems vowels are being replaced with other vowels, but in what way?
    they have to be replaced using strings

  6. #6
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    > they have to be replaced using strings
    And? Did I say otherwise?

  7. #7
    Registered User
    Join Date
    Oct 2007
    Posts
    2
    Err... no... it's not a homework. Sorry if the question was rather stupid. Here is what I made. I did it according to what a fellow colleague said to me. However, the expected result does not happen. What commands should I add or replace?

    Code:
     
    #include <stdio.h>
    #include <string.h>
    #include <conio.h>
    
    main ()
    {
    	char strsource [40];
    	
    	char strdest [40];
    
    	char a, e, i ,o, u;
    
    	printf("\n\nPlease enter your name:");
    	scanf("%s", &strsource);
    	
    	strcpy (strdest, strsource);
    
    	a='e';
    	e='i';
    	i='o';
    	o='u';
    	u='a';
    
    	strncpy(strdest, strsource, 40);
    
    	printf("\n\nYour Star Wars name is:%s\n\n", strsource, strdest);
    
    	getch();
    }

  8. #8
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    um, where do you replace the vowels?

    Use fgets() to read in the string to prevent buffer overflow, copy that to another variable and loop through the other variable character-by-character replacing vowels.

  9. #9
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    BTW, you don't need conio.h, main also must return an int, see the FAQ.
    Last edited by zacs7; 10-25-2007 at 12:09 AM.

  10. #10
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    Quote Originally Posted by modstar89 View Post
    Err... no... it's not a homework.
    Don't lie about it; we're not that stupid! Just ask for someone to nudge you in the right direction. We're allowed to provide some assistance if you show you're making an effort, but certainly cant just give you the answers.

    So many people write exactly this, which is a dead giveaway:
    I need to create a program
    If it was because you wanted to teach yourself to program then you would have used the word 'want' instead. Also it can't be for a job because the level of programming is that of someone's first program ever, let alone their first program in C.

    So, I presume you are supposed to know about loops already? You'll need one of those. You need to look at each character that was typed into the array and do something with it.
    Last edited by iMalc; 10-25-2007 at 12:27 AM.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  11. #11
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > pls. answer his question.. pleeeeaaaaaase...
    Would that be because it is also your question as well?

    I suppose it is mere coincidence then that you both have consecutive member ID's, have the same question to answer, and both posted from the same IP address (oh yes).

    @both of you.
    You need something along the lines of
    if ( str[pos] == 'a' ) str[pos] = 'e';
    to perform a letter substitution.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replacing Characters
    By carrotcake1029 in forum C Programming
    Replies: 3
    Last Post: 04-28-2008, 01:08 PM
  2. Counting Vowels within a string.
    By patso in forum C Programming
    Replies: 12
    Last Post: 04-09-2008, 04:21 PM
  3. Count the number of vowels, consonants, digits etc.
    By kumar14878 in forum C Programming
    Replies: 3
    Last Post: 05-09-2005, 12:34 AM
  4. Replies: 1
    Last Post: 03-06-2005, 10:12 AM
  5. counting vowels
    By trippedwire in forum C++ Programming
    Replies: 10
    Last Post: 10-01-2004, 11:58 PM