struct

This is a discussion on struct within the C++ Programming forums, part of the General Programming Boards category; Hi - Can anyone help me with struct. I've been asked to write a program to add and remove a ...

  1. #1
    kit
    kit is offline
    Registered User
    Join Date
    Oct 2001
    Posts
    6

    struct

    Hi -

    Can anyone help me with struct. I've been asked to write a program to add and remove a list of records (ie. a database). Each record will contain a name, id, gpa, etc... The requirement for it -
    1) Each record should be stored as a struct. 2) The database should be another struct, where one member is an array of records.

    Can I do something like this:

    struct record{
    char name[maxLength]; //would this work???
    int id;
    double gpa;
    ........
    };

    Thanks in advance.

  2. #2
    Anti-Terrorist
    Join Date
    Aug 2001
    Location
    mming, Game DevelopmentCSR >&<>&2Minimization of boolean functions, PROM,PLA design >&0>&WA, USA guitar, dogsCommercial Aviation >&>>&USAProgramming
    Posts
    742
    My guess is that you declare your structure:
    Code:
    struct record{ 
    char name[maxLength];  
    int id; 
    double gpa; 
    };
    Than your database is an array of structures defined in the main function:
    Code:
    int main()
    {
       struct record Database[100];
       ...
       return 0;
    }
    Although this is not proficient, it is the learning stage for working with structures using static memory constraints. This type of excercise will lead into dynamic memory allocation and abstract data types.
    I compile code with:
    Visual Studio.NET beta2

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 1
    Last Post: 12-03-2008, 02:10 AM
  2. Global Variables
    By Taka in forum C Programming
    Replies: 34
    Last Post: 11-02-2007, 03:25 AM
  3. Replies: 10
    Last Post: 05-18-2006, 11:23 PM
  4. What's wrong with my search program?
    By sherwi in forum C Programming
    Replies: 5
    Last Post: 04-28-2006, 09:57 AM
  5. Tutorial review
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 11
    Last Post: 03-22-2004, 08:40 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21