如何将字符串中的元音更改为符号?

ado*_*tyd 3 c loops

我需要将字符串中的元音更改为使用C的$.我知道我需要使用for循环,我很确定我是在正确的轨道但我无法让它工作.

这是我的代码:

#include <stdio.h>
#include <string.h>

int main(void)
{
    char input[50];
    char i;
    int j = 0;

    printf("Please enter a sentence: ");
    fgets(input, 50 , stdin);

    for (j = 0; input[i] != '\0'; j++)      
        if (input[i]=='a'||input[i]=='e'||input[i]=='i'||input[i]=='o'||input[i]=='u')
        {
            input[i]= '$';
            printf("Your new sentence is: %s", input);
        }

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

我知道我的错误不是很大,但我看不出来.这是家庭作业,所以我不想要一个解决方案,只是一些建议,以便我可以从中学习.

编辑:
感谢那些家伙,我摆脱了'j',现在它可以运行但是当我运行程序时,它会为每个元音输出一个新行.我如何编码它以便它只输出最后一行,即所有的元音都改变了?

MBy*_*ByD 6

你对索引犯了一个小错误:

for (j = 0; input[i] != '\0'; j++)
     ^                        ^
Run Code Online (Sandbox Code Playgroud)

应该

for (i = 0; input[i] != '\0'; i++)
Run Code Online (Sandbox Code Playgroud)

实际上,你可以省略j:

int main(void)
{
    char input[50];
    int i;

    printf("Please enter a sentence: ");
    fgets(input, 50 , stdin);

    for (i = 0; input[i] != '\0'; i++)
    {
        if (input[i]=='a'||input[i]=='e'||input[i]=='i'||input[i]=='o'||input[i]=='u')
        {
            input[i]= '$';
        }
    }
    printf("Your new sentence is: %s", input);
    return 0;
}
Run Code Online (Sandbox Code Playgroud)