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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T01:42:23+00:00 2026-06-01T01:42:23+00:00

//Good day. This is just a part of my source code. My main predicament

  • 0

//Good day. This is just a part of my source code. My main predicament is that the print_list function only prints the first input of the user in the linked list. I can’t seem to pin point the problem as the logic of the function seems right. The insert_list function seems to work fine too but I’m not that sure.

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

//this is the node

typedef struct node
{
        char name[61];
        int month;
        int day;
        int year;
        struct node *next;
}node;

//this is the list

typedef struct list
{
        node *head;
        node *tail;
}list;

//this creates the node by accepting the user’s input and puts them in the node

node *create_node()
{
        int x;
        node *data = (node*) malloc(sizeof(node));
        printf("Name: ");
        fgets(data->name, 61, stdin);
        printf("Birthdate (mm/dd/yyyy): ");
        scanf("%d%*[/]%d%*[/]%d", &data->month, &data->day, &data->year);
        getchar();
        if ((data->month)==0||(data->month)>=13||(data->day)<=0||(data->day)>=32||(data->year)<=1977||(data->year)>=3001)
        {
                while ((data->month)==0||(data->month)>=13||(data->day)<=0||(data->day)>=32||(data->year)<=1977||(data->year)>=3001)
                {
                        printf("Invalid Input.\n");
                        printf("Please Enter a Valid Birthdate(mm/dd/yyyy): \n");
                        scanf("%d%*[/]%d%*[/]%d", &data->month, &data->day, &data->year);
                        getchar();
                }
        }
        printf("******************************************************************\n");
        for (x=0; x<=strlen(data->name); x++)
        {
            if (data->name[x]=='\n')
            {
                    data->name[x]='\0';
            }
    }
    printf("Birthday reminder for %s is added.\n", data->name);
    return data;
}


list *create_list(list *plist)
{
        plist->head = NULL;
        plist->tail = NULL;
        return plist;
}

//this inserts the node in the list

list *insert_list(list *plist, node *pnode, node *new_node)
{
    if(plist->head==NULL)
    {
            plist->head=new_node;
            new_node->next=NULL;
    }
    else
    {
            new_node->next = NULL;
            pnode->next = new_node;
            plist->tail = new_node;
    }
    return plist;
}

//this prints the list

list *print_list(list *plist)
{
        node *current = plist->head;
        int i;
        for(i=1;current!=NULL;i++)
        {    
            printf("[%d] %s\n",i ,current->name);
            printf("Birth Date: %d/%d/%d\n", current->month, current->day, current->year);
            current=current->next;
    }
}

//this deallocates the list

list *free_list(list *List)
{
    node *current = List->head;
    node *temp = NULL;
    while(current != NULL)
    {
            temp = current;
            current = current->next;
            free(temp);
    }

    List->head = NULL;
    List->tail = NULL;
}

//this is the main

int main(void)
{
        list* List = (list*) malloc(sizeof(list));
        List = create_list(List);
        char x;
        node *data = (node *) malloc(sizeof(node));
        printf("******************************************************************\n");
        printf("                    ADD BIRTHDAY REMINDER FORM\n");
        printf("******************************************************************\n");
        List = insert_list(List, data, create_node(data));
        printf("Would you like to add another(y/n)?\n");
        scanf("%c", &x);
        if (x=='y')
        {
                while (x=='y')
                {
                        if (x=='y')
                        {
                                getchar();
                            printf("******************************************************************\n");
                                node *data = (node *) malloc(sizeof(node));
                                List = insert_list(List, data, create_node(data));
                                printf("Would you like to add another(y/n)?\n");
                                scanf("%c", &x);
                        }
                }
        }
    print_list(List);
    free(List);
    return 0;

}

//this code is ready for compilling

  • 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-01T01:42:24+00:00Added an answer on June 1, 2026 at 1:42 am

    I do not understand, what do you intend by pnodein insert_list, and I guess, there is the error. Probably, you mean something like previous node. However, the tail is already the previous node. In addition, you use an empty node there, even you alloc memory for a node in create_node. Maybe, the following code would be more appropriate:

    list *insert_list(list *plist, node *new_node)
    {
        if(plist->head==NULL)
        {
                plist->head=new_node;
                plist->tail=new_node;
                new_node->next=NULL;
    
        }
        else
        {
                new_node->next = NULL;
                plist->tail->next = new_node;
                plist->tail = new_node;
        }
        return plist;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Good day, first I would like to tell that I am not proud to
Good day to all. I have this setup: One page with text/whatever, that also
I have this string @[123:peterwateber] hello! good day! I wanna change it to <a
Good day all; I am not sure what has changed to prevent this from
Good day... I have huge trouble with this and it drives me insane. My
Good Day . I just wanna ask about adding days in a given date.
Good day, I am writing a simple CLI (command-line interface) application that provides a
Good day, I have a project that requires that I share the design portion
Good day, We just converted our web application .NET 1.1 to .NET 2.0. We
Thank you for your time, I have spent a good part of my day

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.