How to create an array of records

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Spenca
    New Member
    • Apr 2010
    • 3

    #1

    How to create an array of records

    I am to create an array of records, for students including the basic info-ID, First&Lastname, DOB,address,tel e number,program doing. Whats the correct approach to doing this?
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    Is this to be an array on the stack or the heap?

    On the stack (a local variable):

    Code:
    struct MyStruct
    {
        /* etc...*/
    };
    
    MyStruct array[10];     //an array of 10
    Or the heap:

    Code:
    MyStruct* array = malloc(10 * sizeof(MyStruct));

    Comment

    • Spenca
      New Member
      • Apr 2010
      • 3

      #3
      thanx 4the help weaknessforcats but I'm stil not clear or not sure if i asked the ques properly but ere it is. Create&populate an array of records. Store records into file. Records should include;ID,Fnam e,Lname,DOB,Add ress,tele.

      Comment

      • jkmyoung
        Recognized Expert Top Contributor
        • Mar 2006
        • 2057

        #4
        How do you want to store the records:
        As a comma delimited file? (.csv)
        As XML?
        As binary?
        Other?

        Comment

        • weaknessforcats
          Recognized Expert Expert
          • Mar 2007
          • 9214

          #5
          Presumably you would use a struct for your data variables. Then create an array of this struct.

          You will need to format your output file in such a way so that you can read the data back. You can never read data back unless you already know how it was written.

          Comment

          • Spenca
            New Member
            • Apr 2010
            • 3

            #6
            I'm doing it on a stack and as binary.

            Comment

            • weaknessforcats
              Recognized Expert Expert
              • Mar 2007
              • 9214

              #7
              Let's see your code so far.

              Comment

              Working...