Identifying size of structure arrays

This is a discussion on Identifying size of structure arrays within the C Programming forums, part of the General Programming Boards category; I would like to receive an unknown array of structures as a parameter in a function and identify how many ...

  1. #1
    Registered User
    Join Date
    Feb 2003
    Posts
    2

    Identifying size of structure arrays

    I would like to receive an unknown array of structures as a parameter in a function and identify how many arrays of that structure have been passed? How do I do it?

    For e.g,

    struct tag1 {
    char fld1 [10];
    char fld2[10];
    };

    struct tag1 st[10];

    main()
    {
    func1(st);
    }

    func1(struct tag1 *ptr)
    {
    // how do I identify here that there are 10 arrays of this
    // structure???
    }

  2. #2
    Registered User Cela's Avatar
    Join Date
    Jan 2003
    Posts
    362
    Add one more element to the structure to mark it as the end of the array. Then just loop through the array and test for that marker. :-)
    *Cela*

  3. #3
    Registered User
    Join Date
    Feb 2003
    Posts
    2
    Thanks. And yes; this is one of the solutions that I'm considering, the other being having the caller pass another parameter telling me how many arrays are being passed. But, I just want to make sure that there is no other way to handle this situation.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Heapsort
    By xENGINEERx in forum C Programming
    Replies: 2
    Last Post: 03-30-2008, 08:17 PM
  2. Invalid conversion from 'void*' to 'BYTE' help
    By bikr692002 in forum C++ Programming
    Replies: 9
    Last Post: 02-22-2006, 11:27 AM
  3. Size of structure in bytes
    By Micko in forum C Programming
    Replies: 2
    Last Post: 11-29-2004, 10:09 AM
  4. reading structured arrays, changing their structure
    By _kevin007 in forum C Programming
    Replies: 6
    Last Post: 05-15-2003, 04:49 PM
  5. size of integer arrays
    By steve8820 in forum C++ Programming
    Replies: 2
    Last Post: 03-06-2002, 07:31 PM

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