Search C Program | nimishsoft@gmail.com

String Compare Ignore Case - STRICMP

/* STRING COMPARE IGNORE CASE - STRICMP */

#include<stdio.h>

int main()
{
 char str1[100], str2[100];
 int i, d=0, flag=0;
 char x,y;
 printf("Please enter first string: ");
 // gets(str1); 
 // fgets is a better option over gets to read multiword string .
 fgets(str1, 100, stdin);
 // Following can be added for extra precaution for '\n' character
 // if(str1[length(str1)-1] == '\n') str1[strlen(str1)-1]=NULL;

 printf("Please enter second string: ");
 // gets(str2); 
 fgets(str2, 100, stdin);
 // if(str2[length(str2)-1] == '\n') str2[strlen(str2)-1]=NULL;

 for(i=0;str1[i]!=NULL&&str2[i]!=NULL;i++)
 {
  x=str1[i];
  y=str2[i];
  if(x>='a'&&x<='z')
   x-=32;
  if(y>='a'&&y<='z')
   y-=32;
  if(x!=y)
  {
   break;
   flag=1;
  }
 }
 if(flag=0)
 {
  x=str1[i];
  y=str2[i];
  if(x>='a'&&x<='z')
   x-=32;
  if(y>='a'&&y<='z')
   y-=32; 
 }
 d=x-y;
 
 if(d==0)
  printf("Strings are equal");
 else
  printf("Strings are not equal");

 return 0;
}

6 comments:

  1. what is meant by string compare ignore case

    ReplyDelete
  2. difference string compare case and string compare ignore case

    ReplyDelete
  3. write a program to remove adjacent duplicate character from a string
    ex-abbcddef

    ReplyDelete
  4. please include sample output also its helpful for us

    ReplyDelete
  5. This is probably the least readable code, I've seen.

    ReplyDelete