I tried this small code to use compound literals in IF statement:
#include<stdio.h>
struct time
{
int hour;
int minutes;
int seconds;
};
int main(void)
{
struct time testTimes;
testTimes = (struct time){12,23,34};
if (testTimes == (struct time){12,23,34})
printf("%.2i:%.2i:%.2i\n", testTimes.hour, testTimes.minutes, testTimes.seconds);
else
printf("try again !\n");
return 0;
}
It didn't work. it gave following message on compilation:
prac.c:15:16: error: invalid operands to binary == (have ‘struct time’ and ‘struct time’)
Is it not allowed to use compound literals in IF statement or the syntax is not correct?