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 8684827
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T22:24:16+00:00 2026-06-12T22:24:16+00:00

I am trying to get this code to verify that the user input a

  • 0

I am trying to get this code to verify that the user input a value. It works if i use gets() but when I change it to fgets() it stops working. I want it to keep looping until the user enters a string of at least 1 character but less than 25 I am new to programming if it isn’t apparent in my code. Thanks!

int main(void)
{
    char input[25], inputNew[25];
    int i;
    int x;
    int y;
    do
    {
        printf("Please enter a string less then 25 characters!\n");
        fgets(input, sizeof(input), stdin);  
        y = strlen(input);  
    }
    while(y>25 || y<=0);

    for (i = 0; i <= strlen(input); i++)
    {
        inputNew[i] = toupper(input[i]);
        for (x = 1; x <= strlen(input); x+=2)
        {
        inputNew[x] = tolower(input[x]);
        }
    }
    printf("The new value is: %s.\n", inputNew);
return 0;
}
  • 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-06-12T22:24:17+00:00Added an answer on June 12, 2026 at 10:24 pm

    fgets keeps the ending newline, whereas gets throws it out.

    Therefore, you’ll have to change your check to y <= 1 if you use fgets.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to get this C++ code to input a series of numbers from
I'm trying to play video from youtube using this code but I get this
Forgive me for this unbeautiful code, but I'm trying to get it to work
I'm trying to use the animal sniffer Maven plugin to verify that code is
i am new in programming under linux and trying to get working this code:
I am trying to get this piece of code working in C#, what I
I am trying to get the results of this code this way: title: Ben
I'm trying to write this code using mostly arrays. I'm trying to get Correct
Im trying to get random number between -5 and 5. Im using this code:
I get this error when trying to make the executable, the code compiles correctly

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.