Thread: structure question

  1. #1

    Unhappy structure question

    I have this structure set up to answer a question to set up a structure which has a fix no of students, I think this is right, then comes the second part,

    #include <stdio.h>
    #define MAX_stud 100

    struct student
    char fName[20];
    char sName[20];
    char coursecode[3];
    char feespaid[3];
    int mark[3];
    struct student studall [MAX_stud];



    The seccond part says that I have to make another structure in C to hold the same info but that the no of students changes. Not sure how to go about this, can you help?

  2. #2
    Registered User billholm's Avatar
    Join Date
    Apr 2002


    You should use dynamic memory allocation (linked lists) and you won't have to use #define MAX_stud 100 at all
    All men are created equal. But some are more equal than others.

    Visit me at

  3. #3
    Registered User stautze's Avatar
    Join Date
    Apr 2002
    He says that he has a fixed number of students. In this case it is more efficient to use an array or contiguous list, rather than a linked list.
    'During my service in the United States Congress, I took the initiative in creating the Internet.' - Al Gore, March 9, 1999: On CNN's Late Edition

  4. #4
    Registered User
    Join Date
    Dec 2001


    I want to know how to do this without a fixed No I think that the struct that I have works for a fixed no. (correct me if I am wrong) but my knowledge of linked lists is not very good and have been messing around with them now for a few hours, not getting anywhere fast. It seams to me that these are good for adding in elements but I already know my fixed no of elements them being :

    char fName[20];
    char sName[20];
    char coursecode[3];
    char feespaid[3];
    int mark[3];

    It is a variable no of students that I have to cater for???

  5. #5
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    >It is a variable no of students that I have to cater for???
    Multiple students == Multiple structs. Therefore you need to either use an array(fixed size), dymanic array, link list, binary search tree etc etc. Read up about them, pick one and write some code. Post here when you have problems.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  6. #6
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    >Multiple students == Multiple structs.
    Correction, multiple students == multiple struct instances. Which screams linked data structure to me. But without more code, we can't really help you much since linked lists tend to be a difficult topic for new people and a specific question is easier to answer than trying to post the whole of linked list theory.

    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 13
    Last Post: 12-14-2007, 03:34 PM
  2. Simple C# structure question
    By sketch in forum C# Programming
    Replies: 4
    Last Post: 09-14-2007, 04:29 PM
  3. data structure question
    By miami_victor in forum C++ Programming
    Replies: 13
    Last Post: 12-31-2004, 12:56 AM
  4. Array and Structure Question
    By loopshot in forum C++ Programming
    Replies: 2
    Last Post: 10-21-2004, 05:10 PM
  5. structure question
    By Unregistered in forum C Programming
    Replies: 1
    Last Post: 12-03-2001, 09:04 PM