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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T16:39:33+00:00 2026-05-27T16:39:33+00:00

I am only allowed to use following headers #include <stdio.h> #include <stdlib.h> and I

  • 0

I am only allowed to use following headers

#include <stdio.h>
#include <stdlib.h> 

and I defined my struct student as following:

struct dict
{
    char* word;
    struct dict* link;
};

There are many functions, but only one function that I have problem right now.
This function inserts a struct dict with certain name at the end of the link.

struct student *Linsert(struct dict *list, char *name)
{
    struct student *pnew;
    struct student *pn;
    int exist = 1;

    pnew = (struct dict *)malloc(sizeof(struct dict));
    pnew -> next = NULL;
    pnew -> name = name;

    if (list != NULL)
    {
        for (pn = list; pn -> next != NULL; pn = pn -> next) ;
        pn -> next = pnew;
    }
    else
        list = pnew;

    return list;
}

Using the following function,

//print all the values in the list
void printList(struct dict* list);

I did this:

int main(void)
{

    struct dict *list = NULL;

    char *name;

    while (1) {
        scanf("%s", name);
        if (name == 'Q')
            break;

        list = Linsert(list, name);
        printList(list);
    }
    return 0;
}

Lets say for input, I typed three
apple banana and orange, my result shows three of my last input.

What is the issue here?

  • 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-27T16:39:33+00:00Added an answer on May 27, 2026 at 4:39 pm

    Your main snippet alone has a whole bunch of problems:

    • name is an uninitialized pointer; it’s pointing to some unknown location in memory that you haven’t allocated and are allowed to use, therefore causing undefined behaviour. Perhaps you want char name[20] to allocate an array of 20 chars on the stack, and have scanf store the input in this buffer.

    • You’re comparing a char* (a pointer to the start of a string) to a single char 'Q' – you’re comparing a pointer and an integer value as your compiler warnings will tell you. You’re not comparing the contents of the string for the value 'Q', you’re comparing the memory address of name and the integer value for 'Q'. If you want to compare the string name with the string "Q", use strcmp and check for a return value of 0.

    You also want to be making a copy of the variable passed to Linsert otherwise, as you’ve noticed, you’ll be passing a pointer to the same location in memory every time, and a change to this block of memory will change each of your items.

    If you turn your compiler warnings up you’ll get even more warnings.

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

Sidebar

Related Questions

I am only allowed to use private members in the programming course I'm taking,
How do I create a MS SQL server user that only allowed to read
I need some help with a textbox: The textbox is only allowed to contain
I have a requirement that a user is allowed only to enter string value
I have an asmx web service that should only be allowed to respond to
In my company, these rules apply: Only testers are allowed to create issues. Developers
W3 specifies that only four CSS rules are allowed for table columns (with the
Are these nested comments allowed in a XML file? <!-- Making only one observation
I am confused on the following: To use threads in a Java program, the
As you know, it is not allowed to use the Array-initialisation syntax with Lists.

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.