title: c program for word ladder
body: <p>I have written C code for word ladder.
  It is validating for given test cases. but for 1 test case it's output is wrong I'm not getting where should I make changes.</p>
  
  <p>Question</p>
  
  <blockquote>
    <p>There is a class of word puzzles where you are given two words, such as BEAK and MAKE, and have to get from one to another by changing one letter at a time. Solving such puzzles requires a good vocabulary and some lateral thinking, but checking the solution once you have one is merely tedious and suitable for a computer to do. Note that even correct solutions are not guaranteed to be minimal.</p>
    
    <p>A solution is correct if, for each pair of adjacent words in the ladder, the following apply:</p>
    
    <ul>
    <li>they are the same length</li>
    <li>there is exactly one letter changed.</li>
    </ul>
    
    <p>Write a program that will check proposed solutions.</p>
    
    <p><strong>Input Format:</strong></p>
    
    <p>Input will be a solution i.e it consists of a series of words, one per line, terminated
    by a line containing a single #. A word is a sequence --- between three and twenty uppercase letters.</p>
    
    <p><strong>Output Format:</strong></p>
    
    <p>Output the word ‘Correct’ or ‘Incorrect’ as appropriate.</p>
    
    <p>Sample Input 1:</p>
  </blockquote>
  
  <pre>BARK
  BARE
  #</pre>
  
  <blockquote>
    <p>Sample Output 1:</p>
  </blockquote>
  
  <pre>Correct</pre>
  
  <blockquote>
    <p>Sample Input 2:</p>
  </blockquote>
  
  <pre>MAKE
  BAKE
  BONK
  BONE
  BANE
  #</pre>
  
  <blockquote>
    <p>Sample Output 2:</p>
  </blockquote>
  
  <pre>Incorrect</pre>
  
  <p>My code</p>
  
  <pre><code>#include&lt;stdio.h&gt;
  #include&lt;string.h&gt;
  int main()
  {
    int i,count;
    char a[100],b[100],c[100];
    int flag=1;
    scanf("%s",a);
    do
    {
   scanf("%s",b);
      if(b[0]=='#')
     break;
      if(strlen(a)==strlen(b))
      {  i=0,count=0;
       while(a[i]!='\0')
       {
  
         if(a[i]!=b[i])
           count++;
           if(count==2)
           {
           flag=0;
           }
  
         i++;
       }
     }
      else
      {
        flag=0;
      }
      scanf("%s",a);
      if(a[0]=='#')
        break;
     //  scanf("%s",c);
     strcpy(c,a);
     strcpy(a,b);
      strcpy(b,c);
  
     }
     while(a[0]!='#');
    if(flag==1)
     printf("Correct");
    else
      printf("Incorrect");
     return 0;
     }
  </code></pre>
  
  <p>programs output is incorrect for this input</p>
  
  <blockquote>
    <p>code -> cade -> cate -> date -> data</p>
  </blockquote>