Structure Records (Beginner)

This is a discussion on Structure Records (Beginner) within the C Programming forums, part of the General Programming Boards category; I want to be able to determine how many records are in a structure already. struct carrecords { char make[50]; ...

  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,386
    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,796
    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, 05:21 AM
  2. reading a file into a block
    By mickey0 in forum C++ Programming
    Replies: 19
    Last Post: 05-03-2008, 06:53 AM
  3. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 07:39 AM
  4. Deleting Records from a structure
    By Simon in forum C Programming
    Replies: 5
    Last Post: 09-12-2002, 12:28 AM
  5. Serial Communications in C
    By ExDigit in forum Windows Programming
    Replies: 7
    Last Post: 01-09-2002, 10:52 AM

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