Thread: Structure Records (Beginner)

  1. #1
    Registered User
    Join Date
    Nov 2001
    Posts
    6

    Question Structure Records (Beginner)

    I want to be able to determine how many records are in a structure already.

    struct carrecords
    {
    char make[50];
    char model[50];
    char yearreg[10];
    char regmark[10];
    char mileage[10];
    char price[10];

    }record[30]

    How do I determine how many of record[] I've added already?

    Thanks

    Zac

  2. #2
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,380
    You have an array of structures. Initialize the array with NULL-pointers and add structures. If a structure will be deleted, then make this a NULL pointer. In that way you can just count the pointers not pointing to NULL.

  3. #3
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    Or you could make a sentinel value that is flagged true if the record is filled, false if it isn't. This is a little bit easier than fooling around with NULL pointers.
    Code:
    struct Record
    {
      int isFilled :1;
      int data;
    } static rec[SIZE];
    
    /* To flag true */
    rec[0].isFilled = 1;
    
    /* To check all records */
    for ( i = 0; i < SIZE; i++ )
      if ( rec[i].isFilled & 1 ) flag++;
    -Prelude
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 1
    Last Post: 03-27-2009, 04:21 AM
  2. reading a file into a block
    By mickey0 in forum C++ Programming
    Replies: 19
    Last Post: 05-03-2008, 05:53 AM
  3. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  4. Deleting Records from a structure
    By Simon in forum C Programming
    Replies: 5
    Last Post: 09-11-2002, 11:28 PM
  5. Serial Communications in C
    By ExDigit in forum Windows Programming
    Replies: 7
    Last Post: 01-09-2002, 10:52 AM