Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6836559
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:22:12+00:00 2026-05-26T23:22:12+00:00

I need to change the vowels in a string to a $ using C.

  • 0

I need to change the vowels in a string to a $ using C. I know that I need to use a for loop and I’m pretty sure I’m on the right track but I can’t get it to work.

Here is my code:

#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;
}

I know my error is not a big one but I just can’t see it. This is homework so I don’t want a solution as such just some advice so that I can actually learn from this.

Edit:
Thanks for that guys I got rid of ‘j’ and it now works however when I run the program it outputs a new line for every vowel it changes. How do I code it so that it only outputs the final line i.e. with all of the vowels changed?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T23:22:12+00:00Added an answer on May 26, 2026 at 11:22 pm

    You made a small mistake with the index:

    for (j = 0; input[i] != '\0'; j++)
         ^                        ^
    

    should be

    for (i = 0; input[i] != '\0'; i++)
    

    Actually, you can omit 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;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to change Activity to ListActivity. But I can't start my project... do
I need to change some primary keys from non-clustered to clustered but I can't
I need change the background image, so I using: $('body').css({backgroundImage : 'url(images/wallpaper/'+wp+'.jpg)'}); But, I
I need change background of all text that have two spaces from the start
I need to change an element's ID using jQuery. Apparently these don't work: jQuery(this).prev(li).attr(id)=newid
I need to change the app name based on what configuration I'm using in
I need to change the order of headers, I'm using this: HttpWebRequest request =
I need to change the folder that relative include paths are based on. I
I need to change some characters that are not ASCII to '_'. For example,
I need change or remove <title> tag in wordpress using plugin for example <title>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.