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

  • Home
  • SEARCH
  • 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 3425672
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T06:37:20+00:00 2026-05-18T06:37:20+00:00

I have a struct called student as such: struct student{ char*lastName; char*firstName; int age;

  • 0

I have a struct called student as such:

struct student{
   char*lastName;
   char*firstName;
   int age;
   float grade[3];
}

how would i read in a text file which should be read into an array of student records. All students’ age should be randomly generated ranging from 18 to 35. each student has 3 text grades from 0 to 100.

  • 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-18T06:37:20+00:00Added an answer on May 18, 2026 at 6:37 am

    First of all, if I understand your question, you’re supposed to provide a linked list. Since linked lists are trickier than reading a file, generating numbers and so on, I’ll only give you hints about that.

    If you had to put your students in a simple array, it would be easy, a simple student myArray[100], for instance, would do it.
    It would mean that all your students would be stocked in the same part of the memory. Like that : (A)(B)(C). A, B and C are three students, stocked next to each other. This is not convenient if you’re going to have a vast number of students, since you’ll have to find a big enough zone in the memory to stock everything. This is why there are linked list : so you can put your students everywhere in the memory. For instance : (A) (some other data) (B) (some other data) (C). There, you do not need to have a big, unique, free space in your memory.

    But there is a problem : when you’re using an array, it is very easy to find your datas. You just need to know the beginning of the array, and then, calculate the number of the data you want starting from the first item of the array. This is what it means when you’re doing : myArray[4], for instance.

    Since you’re going to use a linked list, you can’t calculate where the datas are, because, and that’s the idea of the linked list, they could be anywhere. That’s why the list is linked : you need to provide a way to go from datas to datas. And you’re going to use C programmers best-friends : pointers.

    So you have to improve your struct :

    struct student{ 
       char* lastName; 
       char* firstName; 
       int age; 
       float grade[3]; 
       student* next
    } 
    

    And you’re going to need a very important variable : student* listStart. This is the equivalent of the “array” variable you’re using. The place where you’re going to need to start if you want to access your data.

    Now, what you have to do basically :

    1. Read the file where your students are stored.
    2. For each student, use a malloc() to allocate enough memory for this student (study how malloc() work, it’s extremely important).
    3. If this is the first student, listStart points towards this student.
    4. For this newly created student, fill all the fields (name, grades, etc.). Fill the “next” pointer of the previousstudent with the adress of this student. The “next” pointer of the student you’re creating should be “NULL”, in case it’s the end of the list.

    All right, it’s a bit confusing at first. But if you manage to do this, you’ll have learn something useful, without us doing your homework for you. Good luck;

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

Sidebar

Related Questions

I have this struct: struct Map { public int Size; public Map ( int
Say I have a struct s with an int pointer member variable i. I
I have the following struct in C++: #define MAXCHARS 15 typedef struct { char
I have a struct called Point. Point is pretty simple: struct Point { Row
I have a struct called coordinate which is contained in a list in another
I have a struct called Point (which happens to be a Python Extension) that
This is really a noob quick question. Imagine you have a struct called No
I am trying to model a network using C++. I have a struct called
Suppose I have a struct called foo_boolean that contains some boolean values: struct foo_boolean
I have a struct defined like follows as part of an object. I'm trying

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.