Comparing Structure Elements 
Author Message
 Comparing Structure Elements

Help Please ...

The following code fragment shows my current way of comparing two
structures to find elements which have the same text identifier
(tag_name). What I am doing is creating a structure which holds a
name and a value, sometime later, another struture is updated with
the same names and new data (.value).

I don't think that this is a very efficient way of doing it, does
anyone have any better solutions that they would like to share ? As
you can probably tell, I have no real experience with
sorting/searching records etc, so any help would be appreciated



#include <stdio.h>
#include <string.h>
#include <stdlib.h>

#define RECORDS 100           /* Could be more though */
#define MAX_FIELD_SIZE 10
#define MAX_LINE_LENGTH 40

typedef struct {
    char tag_name[MAX_FIELD_SIZE+1];
    long value;

pml_data pml_current[RECORDS]; /* Array to hold new PML totals  */
pml_data pml_history[RECORDS]; /* Array to hold old PML totals  */
/* Code to populate the structures is omitted to keep this brief    */

int main()
 int i,j;                      /* loop counters */
 long difference = 0;

 for (i = 0; i < PML_RECORDS; i++)
      for (j = 0; j < PML_RECORDS; j++)
   if ((strcmp(pml_current[i].tag_name,
        pml_history[j].tag_name)) == 0)
     difference = pml_current[i].value
          - pml_history[j].value;
  }   /* j */
 }  /* i */


Tue, 13 Jul 1999 03:00:00 GMT  
 [ 1 post ] 

 Relevant Pages 

1. making pointers to structure elements using array elements

2. Compare element of arraylist with String

3. Question about compare two elements within sturcture?

4. sizeof an element of a structure

5. Help with structure element casting required

6. printing structure elements with MACRO

7. Setting structure array elements

8. Getting address of element of structure array.

9. updating structure elements from a pointer passed to the function

10. Setting elements in a structure array

11. Passing pointers to elements of a structure.

12. Using NULL for optional structure elements


Powered by phpBB® Forum Software