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.
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.
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.
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
And? Did I say otherwise?
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(); }
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.
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.
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: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.I need to create a program
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"
> 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.