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

The Archive Base Latest Questions

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

I am making a linked list of objects. For some reason when i go

  • 0

I am making a linked list of objects. For some reason when i go to print the value of a value within the object (a char array) i’m getting junk printing before the value. Why is this happening and how do i get rid of it? Here is a part of my code:

    int num = 0;
    int input = 1;
    int retval = 0;
    struct PDB2 *llist;
    char avalue[100] = ""; 
    llist = (struct PDB2 *)malloc(sizeof(struct PDB2));
    llist->data1[100] = NULL;
    llist->next = NULL;

     while(input != 0) {
  printf("\n-- Menu Selection --\n");
  printf("0) Quit\n");
  printf("1) Insert\n");
  printf("2) Delete\n");
  printf("3) Search\n");
  printf("4) Display\n");
  scanf("%d", &input);

  switch(input) {
   case 0: 
   default:
    printf("Goodbye ...\n");
    input = 0;
    break;
   case 1:
    printf("Your choice: `Insertion'\n");
    printf("Enter the value which should be inserted: ");

    scanf("%s", &avalue);
    append_node(llist, avalue);
    break;
   case 2:
    printf("Your choice: `Deletion'\n");
    printf("Enter the value which should be deleted: ");
    scanf("%s", &avalue);
    delete_node(llist, avalue);
    break;
   case 3:
    printf("Your choice: `Search'\n");
    printf("Enter the value you want to find: ");
    scanf("%s", &avalue);
    if((retval = search_value(llist, avalue)) == -1)
     printf("Value `%s' not found\n", avalue);
    else
     printf("Value `%s' located at position `%d'\n", avalue, retval);
    break;
   case 4:
    printf("You choice: `Display'\n");
    display_list(llist);
    break;
   } /* switch */
  } /* while */

 free(llist);
 return(0);
}


    void append_node(struct PDB2 *llist, char message[])
{
    int x = 0; 
     while(llist->next != NULL)
     {
         llist = llist->next;
     }

     llist->next = (struct PDB2 *)malloc(sizeof(struct PDB2));

     for(x = 0; x < 100; x++)
     {
        llist->next->data1[x] = message[x]; 
     }
     llist->next->next = NULL;

}
void display_list(struct PDB2 *llist)
{
    while(llist->data1 == NULL)
    {
        llist = llist->next; 
    }
    while(llist->next != NULL) 
    {
      printf("%s ", llist->data1);
      llist = llist->next;
    }
     printf("%s", llist->data1);
}
  • 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:25:00+00:00Added an answer on May 27, 2026 at 4:25 pm

    The char array in your initial node is uninitialized. Change

    llist->data1[100] = NULL;
    

    to

    llist->data1[0] = '\0';
    

    to stop it from being printed.

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

Sidebar

Related Questions

Hi I am making a linked list data structure and within the list I
I'm making a linked list class and am trying to implement this contains() method.
I'm making a linked list (of structs) in C, but I want to be
I have a manager class maintaining a list of objects. Each Object has a
I want to give a certain linked list to a class I am making.
I coded for doubly linked list implementation in C. In that, after making insertion
I am working on a linked list implementation in C++. I am making progress
I'm quering the table MsysObjects for making a list of the objects in my
Okay, I'm making a project that implements a Double Linked List using classes, templates
To insert/delete a node with a particular value in DLL (doubly linked list) entire

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.