title: String anagrams C program
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/522112/what-is-an-easy-way-to-tell-if-a-list-of-words-are-anagrams-of-each-other">What is an easy way to tell if a list of words are anagrams of each other?</a><br>
    <a href="https://stackoverflow.com/questions/4236906/finding-if-two-words-are-anagrams-of-each-other">finding if two words are anagrams of each other</a>  </p>
  </blockquote>
  
  
  
  <p>I have below C code written to check if two given strings are anagrams of each other.
  I know this is worst in terms of complexity/efficiency and there are far many better ways to do it.</p>
  
  <pre><code>#include "stdio.h"
  
  main()
  {
  char s1[]="mist";
  char s2[]="mitt";
  int i,j,isanag=0;
  
  if(strlen(s1)!=strlen(s2))
      printf("Not anagrams\n");
  
  for(i=0;i&lt;strlen(s1);i++)
  {
      isanag=0;
      for(j=0;j&lt;strlen(s2);j++)
      {
          if(s1[i]==s2[j])
          {
              isanag = 1;
              break;
          }
      }
      if(isanag == 0)
      {
          printf("Not anagrams\n");
          getch();
          exit(0);
      }
  
  }
  
  printf("Yes Anagrams\n");
  getch();
  }
  </code></pre>
  
  <p>This works fine and prints Not Anagrams which is correct
  If I swap the names of two strings as below it gives wrong answer</p>
  
  <pre><code>char s1[]="mitt";
  char s2[]="mist";
  </code></pre>
  
  <p>I know the way the 2 for loops are coded this is obvious. </p>
  
  <p>What can I do to improve this code and resolve this quirk?</p>