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

The Archive Base Latest Questions

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

I came up with what I thought was a messy solution to an awkward

  • 0

I came up with what I thought was a messy solution to an awkward (albeit standard) problem:
For a given user input, reverse the letters of the words

E.g:

This is a standard test

becomes

sihT si a dradnats tset

and not

tset dradnats a si sihT

The heart of the matter is this piece of code

  while (!iscntrl(user_input[x])) // quit when new line is read
      {
        restart:
        x++;
        puts("first level test");
        if (user_input[x]==' ')
            {
            puts("second level test");
            for (i=x; user_input[i]!=' '; --i)
                {               
                reverse_words[k]=user_input[i];
                k++;
                puts("third level test");
                goto restart;
                }
            }
        }

(yes, I know, there is a goto in there :/ )

but the third level of the loop is never touched.

Presumably there is something completely wrong with (i=x; user_input[i]!=' '; --i) as a for loop parameter?

x, i, and k are all initialised as integers == 0 prior to the beginning of the first loop.

  • 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-16T02:41:13+00:00Added an answer on June 16, 2026 at 2:41 am

    Well, your condition contradicts here:

     if (user_input[x]==' ')
                {
                puts("second level test");
                for (i=x; user_input[i]!=' '; --i)
    

    You only enter if user_input[x] is space, but you loop as long as it’s not equal to space.

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

Sidebar

Related Questions

i thought i solved this problem by myself but it came back to haunt
I came across this CTE solution for concatenating row elements and I thought it's
When this quick one hour project came up I never thought that 2 days
I came across this code on reddit . I would have thought that type
I recently came along this line of code: CustomData_em_free_block(&em->vdata, &eve->data); And I thought, isn't:
Came across this code: <?php require_once 'HTTP/Session/Container/DB.php'; $s = new HTTP_Session_Container_DB('mysql://user:password@localhost/db'); ini_get('session.auto_start') or session_start();
I thought I understood variable scope until I came across this bit of code:
I came across this recently and thought it would make a great SO question.
I came across this issue recently and thought it was really helpful. My question
I came across this lightbox plugin and thought of implementing it in my project.

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.