# String Compare

• 02-09-2012
shruthi
String Compare
Hi Everyone!
How do I compare the array of strings with a string? I tried with strcmp.I want to check which month has the user entered,accordingly take the number corresponding for the month for calculations.Getting confused when it comes to strings,please help.

Code:

```void get_day(int y,char* m,int d,int lp) {     int c,a,i,cnt=0,b,e,sum,res,z;     int cent[10]={4,2,0,6,4,2,0,6,4,2};     int month_code[12]={0,3,3,6,1,4,6,2,5,0,3,5};     char month[12][5]={"jan","feb","mar","apr","may","jun","july","aug","sept","oct","nov","dec"};     char day[7][10]={"sunday","monday","tuesday","wednesday","thursday","friday","saturday"};     z=y/100;     b=y%100;    //year     c=b/4;     for(i=17;i<=26;i++)     {         if(i==z)         a=cent[cnt];    //century         else         cnt++;     }     printf("a=%d\n",a);     printf("b=%d\n",b);     printf("c=%d\n",c);     printf("d=%d\n",d);     /*if(lp==TRUE)     {         if(*m=='jan')             e=6;         else if(*m=='feb')     }      e=2;     else     {*/         for(i=0;i<12;i++)         {             if(strcmp(month[i],m))      //problem part             {                     printf("val of i=%d\n",i);    //test                     e=month_code[i];                     break;              }         }     //}     printf("e=%d\n",e);     sum=a+b+c+d+e;     res=sum%7;     printf("sum=%d\n",sum);     printf("res=%d\n",res);     printf("The day is %s\n",day[res]); } int leap_year(int year) {     if(year%400==FALSE && year%100!=FALSE || year%4==FALSE)     return TRUE;     else     return FALSE; }```
• 02-09-2012
nonoob
I think you are checking if the strings are equal... so it should be
if (0 == strcmp(month[i], m))
• 02-09-2012
shruthi
Thank you,somehow I overlooked that and thought the problem was with strings.It's working fine now.