Comparing structures?

This is a discussion on Comparing structures? within the C Programming forums, part of the General Programming Boards category; Can I compare the data contents of two structures? For example, if I have Code: typedef struct{ int a; char ...

  1. #1
    Registered User
    Join Date
    Sep 2004
    Posts
    16

    Comparing structures?

    Can I compare the data contents of two structures? For example, if I have
    Code:
    typedef struct{
     int a;
     char b;
    } HELP;
    
    // ........ main:
    HELP stuff1, stuff2;
    can I compare whether stuff1.a==stuff2.a and stuff1.b==stuff2.b? Simply using stuff1==stuff2 results in a compiler error. Must I compare them individually?

  2. #2
    vae victus! skorman00's Avatar
    Join Date
    Nov 2003
    Posts
    594
    you can use memcmp depending on what the data it holds. If it only holds an int and a char, memcmp would be fine.

  3. #3
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. comparing structures
    By sleepywalker in forum C Programming
    Replies: 15
    Last Post: 02-16-2009, 01:15 PM
  2. Replies: 2
    Last Post: 07-11-2008, 07:39 AM
  3. Structures & Comparing
    By Cyber Kitten in forum C Programming
    Replies: 1
    Last Post: 10-22-2001, 11:41 AM
  4. Comparing strings w/in structures
    By vehl in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2001, 10:59 AM
  5. Methods for Sorting Structures by Element...
    By Sebastiani in forum C Programming
    Replies: 9
    Last Post: 09-14-2001, 12:59 PM

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