Array stops scanning after do loop

This is an anagram checker program
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
  #include<stdio.h>
#include<conio.h>
#include<string.h>
#include<iostream>
char str1[30],str2[30];
int length1, length2;
 
int lengthcheck()
{
    int x;
    
    length1 = 0;
    length2 = 0;
    
    for(x=0;x<strlen(str1);x++)
    {
         if(str1[x] != ' ')
              length1 ++;
    }
    
    for(x=0;x<strlen(str2);x++)
    {
         if(str2[x] != ' ')
              length2 ++;
    }
    
    if(length2==length1)
        return 1;
    else
        return 0;
}

int anagramcheck()
{
    int x,y;
    
    length1 = 0;
    length2 = 0;
    
    for(x=0;x<strlen(str1); x++)
	{
		if(str1[x] != ' ')
		{
			for(y=0; y<strlen(str2); y++)
			{
				if(str1[x] == str2[y])
				{
					str1[x] = ' ';
					str2[y] = ' ';
				}
			}
		}
	}

	for(int x = 0; x<strlen(str1); x++)
	{
		if(str1[x] != ' ')
		{
			length1 = 1;
			break;
		}
	}
	
	for(int y = 0; y<strlen(str2); y++)
	{
		if(str2[y] != ' ')
		{
			length2 = 1;
			break;
		}
	}

	if(length1 == 0 && length2 == 0)
		return 1;
	else
		return 0;
}    


main()
{
      char a,repeat;
      do
{
      printf("\n");
      printf("\nEnter first word: ");
      gets(str1);
      strlwr(str1);
      printf("Enter second word: ");
      gets(str2);
      strlwr(str2);
      a = lengthcheck();
      if(a==1)
      {
           a = anagramcheck();
           if(a==1)
           printf("ANAGRAM");
           else
           printf("NOT ANAGRAM"); 
      }
      else
      printf("NOT ANAGRAM");
      
      printf("\nDo you want to try again [Y/N]? ");
      scanf("\n%c", &repeat);
}
while(toupper(repeat)!='N');
      getch();
}


The problem is that, after the do loop, it continues to scan for the 2nd word without scanning for the 1st.

Topic archived. No new replies allowed.