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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T20:30:35+00:00 2026-05-28T20:30:35+00:00

I am trying to make Hello World to World Hello. But the code is

  • 0

I am trying to make “Hello World” to “World Hello”.
But the code is not working properly the way I wanted it to behave.
See the code below:

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
struct llnode
{
    char *info;
    struct llnode *next;
};

typedef struct llnode NODE;

int main()
{
    char msg[50],word[10],*str;
    int i=0,length=0,j=0;
    NODE *ptr,*front=NULL,*temp,*last=NULL;

    //printf("Enter the sentence: ");
    str= "Hello World"; //fgets(msg,sizeof(msg),stdin);

    while(str[i]!='\0')
    {
        if((str[i]==' ')||(str[i]=='\n'))
        {
            word[j]='\0';
            j=0;
            ptr=(NODE *)malloc(sizeof(NODE));
            ptr->info=word;
            ptr->next=NULL;

            if(front==NULL)
            {
                front=ptr; // only change the value of front here;
            }
            else
            {
                temp=front;
                while((temp->next)!=NULL)
                {
                    temp=temp->next;
                }
                temp->next=ptr;
            }
            printf("\n##%s\n",front->info); // prints thewords and not
            //the first word
        }
        else
        {
            word[j]=str[i];
            j++;
        }
        i++;
    }

    temp=front;
    while(temp)
    {
        length++;
        printf("%s ",temp->info);
        temp=temp->next;
    }
    printf("\nLength of Linked List(or, number of words): %d\n",length);

    i=0;
    printf("\n************************\n");

    while(i<length)
    {
        temp=front;
        while(temp->next!=last)
        {
            temp=temp->next;
        }
        last=temp;
        printf("%s ",temp->info);
    i++;
}

return 0;
}

Thanks

  • 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-28T20:30:37+00:00Added an answer on May 28, 2026 at 8:30 pm

    There are a number of things wrong with the code:

    You are using a single word array to read all the words. So, when you read “Hello”, you read into the word array, print “##Hello” and store the pointer to the word array as front->info. Then, you OVERWRITE the word array with World. Also, please note that you NEVER add a node with the word “World” because you exit the loop as soon as you encounter the ‘\0’. So, your linked list contains only one node. But, there is a problem, since you stored a pointer to the word array in the first node and since the word array has been overwritten with “World”, when you exit the loop, there is only one node in the list and the info of this node is word array which contains “World” and not “Hello” like it once did. So, I guess this explains the output?

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

Sidebar

Related Questions

I am trying to make a sample Spring 3 Web Hello World sample but
Hello I am trying to make a C# program that downloads files but I
I'm trying to make a little Hello World webservice with Django following a few
i'm trying to make simple scheduler using Timer and TimerTask classses see the code
After trying to make a while(bool) loop and it failing because I couldn't see
I'm trying to make a meta-language for writing markup code (such as xml and
I'm trying to learn JS, so forgive me if you code makes the world
When trying to compile with Code::Blocks the example that comes up with GTK+: #include
i am trying to write a boot loader(hello world sort). i am using Bochs
Hello I am trying to figure out how to make it so when someone

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.