Equality check in structure in C.

 

01  #include<stdio.h>
02 #include<string.h>
03
04 int isEqual(struct my_struct,struct my_struct);
05
06 struct my_struct
07 {
08 char name[20];
09 int arr[5];
10 }
11 s1={"hello",{1,2,3,4,5}},s2={"hello",{1,2,3,4,5}};
12
13 int main()
14 {
15 if(isEqual(s1,s2))
16 {
17 printf("nStructure Variables are Equal");
18 }
19 else
20 {
21 printf("nStructure Variables are Not Equal");
22 }
23 }
24
25 int isEqual(struct my_struct s1,struct my_struct s2)
26 {
27 int i,count=0;
28 if(!strcmp(s1.name,s2.name))
29 {
30 for(i=0;i<5;i++)
31 {
32 if(s1.arr[i]==s2.arr[i])
33 {
34 count++;
35 }
36 }
37 if(count==5)
38 {
39 return 1;
40 }
41 }
42 return 0;
43 }
 
 OUTPUT :

Structure Variables are Equal

Related Post

Leave a Reply

Your email address will not be published. Required fields are marked *


The reCAPTCHA verification period has expired. Please reload the page.