Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

How to use If...Else statement to compare struct's

Status
Not open for further replies.

vead

Full Member level 5
Joined
Nov 27, 2011
Messages
285
Helped
3
Reputation
6
Reaction score
3
Trophy points
1,298
Location
india
Activity points
3,815
Hello everyone

I want to compare current date with Alarm dates which is in dd/MM/YYYY string format

This is the data structure that is used to store the current date


Code C - [expand]
1
2
3
4
5
typedef struct  {
    int day;
    int month;
    int year;
} Date ;



This is the data structure that is used to store the Alarm date

Code C - [expand]
1
2
3
4
5
typedef struct  {
    int day;
    int month;
    int year;
} Alarm_Date ;



Start function

Code C - [expand]
1
2
3
4
5
int main ()
 
{
 
}



Current date : 01/10/2015

Alarm dates :02/10/2015, 04/10/2015, 06/10/2015

Compare current date with alarm date
If current date match with Alarm date 02/10/2015, than compare next Alarm date

If current date match with Alarm date 04/10/2015, than compare next Alarm date

If current date match with Alarm date 06/10/2015, than compare next Alarm date

How to use If...Else statement to compare current date with Alarm date ?
 
Last edited by a moderator:

Re: How to use If...Else statement to perform the comparison.

Structure is an array of bytes in memory. So, easiest way is to compare them like a string.
 

Re: How to use If...Else statement to perform the comparison.

your both typedef have same members so no need to define them twice..
rather....

Code C - [expand]
1
2
3
4
5
6
7
8
typedef struct
{
uint8_t day,
uint8_t month,
uint8_t year,
}_tdt;
 
_tdt Date,AlarmDate;



- - - Updated - - -

there is a library function (if your compiler supports) memcmp...
search about it...
 

Re: How to use If...Else statement to perform the comparison.

Use the 'strcmp(first string,second string)' command, it returns zero when the two strings are the same.

Brian.
 

Re: How to use If...Else statement to perform the comparison.

Use the 'strcmp(first string,second string)' command, it returns zero when the two strings are the same

I presume, the code author has a reason to use binary records rather than strings to represent the date information, I would also do so. In this case you can use memcmp() to compare the complete records.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top