[ Home  |  FAQ-Related Q&As  |  General Q&As  |  Answered Questions ]


    Search the Q&A Archives


...compare two structures in C without comparing...

<< Back to: comp.lang.c FAQ list Table of Contents

Question by sprasad
Submitted on 9/10/2003
Related FAQ: comp.lang.c FAQ list Table of Contents
Rating: Rate this question: Vote
How to compare two structures in C without comparing individual members


Answer by typo
Submitted on 9/29/2003
Rating:  Rate this answer: Vote
According to the following page on the web, you can't do that.  You just have to write out a function that will compare all the structure members.

http://www.eskimo.com/~scs/C-faq/q2.8.html

 

Answer by naidu_trk
Submitted on 12/23/2003
Rating:  Rate this answer: Vote
There is no such method to compare 2 structures with out comparing their individual fields due to their alignment rules. The size of the structure may be or may not be equal to the sume of the individual sizes of the fields.

 

Answer by MK-2004
Submitted on 3/2/2004
Rating:  Rate this answer: Vote
How you can compare the content of two black boxes if you don't do that for their respective components. Structure is a collection of variables under the same name or a convenient way of grouping several pieces of related information together

A native method do not exist, but can be written for such need.

 

Answer by Sathish
Submitted on 5/10/2006
Rating: Not yet rated Rate this answer: Vote
It can be done by using memcmp(&a, &b, sizeof(the struct))

- Sathish

 

Answer by maddy25
Submitted on 12/15/2006
Rating: Not yet rated Rate this answer: Vote
structures can be compared only by comparing structure members,because the two structures compared may not be of same size.

 

Answer by Bholanath Pal
Submitted on 4/16/2007
Rating: Not yet rated Rate this answer: Vote
use memcmp to compare the structure object.
memcmp returns 0 if both are equal.

try it


 

Your answer will be published for anyone to see and rate.  Your answer will not be displayed immediately.  If you'd like to get expert points and benefit from positive ratings, please create a new account or login into an existing account below.


Your name or nickname:
If you'd like to create a new account or access your existing account, put in your password here:
Your answer:

FAQS.ORG reserves the right to edit your answer as to improve its clarity.  By submitting your answer you authorize FAQS.ORG to publish your answer on the WWW without any restrictions. You agree to hold harmless and indemnify FAQS.ORG against any claims, costs, or damages resulting from publishing your answer.

 

FAQS.ORG makes no guarantees as to the accuracy of the posts. Each post is the personal opinion of the poster. These posts are not intended to substitute for medical, tax, legal, investment, accounting, or other professional advice. FAQS.ORG does not endorse any opinion or any product or service mentioned mentioned in these posts.

 

<< Back to: comp.lang.c FAQ list Table of Contents


[ Home  |  FAQ-Related Q&As  |  General Q&As  |  Answered Questions ]

© 2008 FAQS.ORG. All rights reserved.