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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T07:17:44+00:00 2026-05-21T07:17:44+00:00

Greetings again, I have this problem again on C but now using struct. Having

  • 0

Greetings again,

I have this problem again on C but now using struct.
Having this structure of student

struct student {
   char *name;
   int age;
}

I wanted to a list where I could add a number of Student and can also view all of its elements. Here’s the code I have done so far.

#include<stdio.h>
#include<stdlib.h>
// struct student ...
void add(student **list, char* name, int age) {
   student* temp = (student *)malloc(sizeof(student));
   temp->name = name
   temp->age = age;
   *list = temp;
   *(list++) = (student *)malloc(sizeof(student));
}
void view(student **list) {
   student* data = *list;
   while(data != '\0') { printf("%s%i", data->name, data->age); *(data++); }
}
main() {
   student* list = (student *)malloc(sizeof(student));
   char* name = (char *)malloc(sizeof(char));
   int age=0;
   // inputs for name and age
   // do-while(option != EXIT_VALUE);
   // inside do-while are the following below
   add(&list, name, age);
   view(&list);
}

I only get the newest student upon the view method.

  • 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-21T07:17:45+00:00Added an answer on May 21, 2026 at 7:17 am

    It makes sense, since you are allocation space for 1 single student structure:

    student* list = (student *)malloc(sizeof(student));
    

    You should do something like:

    int list_size = 20;
    student* list = (student *)malloc(sizeof(student) * list_size);
    

    The name variable suffers from the same problem.

    A dynamic linked list should have a reference to the next and previous elements. You’ll have to change your program to work with:

    struct student {
       char *name;
       int age;
       struct student* next;
       struct student* previous;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Greetings, Here's the problem I'm having. I have a page which redirects directly to
Greetings all, I have posted this on the MSDN managed news groups as well
Greetings, In an WPF DataGridTemplateColumn I have a CellTemplate using a ListView and a
Good day once again. I have a (seemingly) simple problem. I'm trying to display
Greetings all. I am writing some code using the Boost Units library and have
Greetings, I'm having problem invoking a richTextBox from a worker thread in C#. I'm
Greetings all, I'm trying to localize a .NET/C# project. I'm using string resource files
Greetings, I have a particular object which can be constructed from a file, as
Greetings again, and thanks once more to all of you who provided answers to
Greetings, We have an application written in .net 3.5 that uses wcf and also

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.