Since there is no such function in C, the programmer must create a function that compares the members.
#include <stdio.h>
#include <stdbool.h>
struct Coord{
int x, y;
};
bool CoordEqual(struct Coord const c1, struct Coord const c2){
return (c1.x==c2.x && c1.y==c2.y);
}
int main(int argc, const char * argv[]) {
struct Coord c1 = {3,5};
struct Coord c2 = {3,5};
struct Coord c3 = {5,3};
printf("c1 == c2: %s\n", CoordEqual(c1,c2) ? "true" : "false");
printf("c1 == c3: %s\n", CoordEqual(c1,c3) ? "true" : "false");
}
© 2024 OneMinuteCode. All rights reserved.