Originally Posted by
quzah
You need to write it out, and then think about what you wrote, what each step means:
Code:
for each letter in the source string ... ok, how do I do that?
if this letter is a vowel ... ok how do I do that?
do a star or whatever ... ok how do I do that?
else
do the opposite of whatever (star/space) ... ok how do I do that?
You can do the first, you just use a
for loop. Now, how do you do the second?
Quzah.
Ok, let see:
for each letter in the source string ... ok, how do I do that?
#1 The source string is char str[100];
#2 Since is for each letter I need to create a for loop
#3 The int i; is the letter and the i++ is for each letter
#4 The str[i] != '\0' is for stopping the loop when the word is at the end of the string
The result:
Code:
for(i=0; str[i] != '\0'; i++)
if this letter is a vowel ... ok how do I do that?
#1 To find if the letter is a vowel I need to compare each character with the other vowel string
#2 To do that I need to create a nested for loop which is:
Code:
for(j=0; strv[j] != '\0'; j++)
#3 Where the int j; is the vowel, j++ is each vowel and the str[j] != '\0' is for stopping the loop when the word is at the end of the string
#4 Now each time the loop is working it should make the comparison with the vowels. For doing that you need to create an if statement in this case:
Code:
if (str[i] == strv[j])
{
printf("*");
}
else do the opposite of whatever (star/space) ... ok how do I do that?
#1 For that I create an else statement:
Code:
else
{
printf(" ");
}
So what's wrong?