I have a function to convert the first 3 letters of the month into a number (Jan = 1, Feb = 2, etc).
int convertDate(char date[3])
{
printf("%s", date);
if(date == 'Ian')
return 1;
else
if(date == 'Feb')
return 2;
else
if(date == 'Mar')
return 3;
else
if(date == 'Apr')
return 4;
else
if(date == 'Mai')
return 5;
else
if(date == 'Iun')
return 6;
else
if(date == 'Iul')
return 7;
else
if(date == 'Aug')
return 8;
else
if(date == 'Sep')
return 9;
else
if(date == 'Oct')
return 10;
else
if(date == 'Noi')
return 11;
else
if(date == 'Dec')
return 12;
else return 0;
}
But, in main() when I use:
printf("%d", convertDate("Ian"));
it returns 0 instead of 1. Same for any other month. Any suggestion?
Use
strcmp()when comparingchar*.if (date == "Sep")compares the base address of thechar*.