-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathZ12.c
More file actions
75 lines (74 loc) · 1.61 KB
/
Z12.c
File metadata and controls
75 lines (74 loc) · 1.61 KB
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
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
int tolower(int c);
void comparsion(char a[], char b[])
{
for(int i=0; i<strlen(a); i++)
{
if(a[i]>=97 && a[i]<=122)
{
for(int j=0; j<strlen(b); j++)
{
if(a[i]==b[j])
{
a[i]=' ';
b[j]=' ';
}
}
}
}
}
int check(char a[], char b[])
{
for(int i=0; i<strlen(a)-1; i++)
{
if(a[i]!=' ' || b[i]!=' ')
{
return 0;
}
}
return 1;
}
void remove_blanks(char a[], char b[])
{
int c=0, d=0;
while (a[c] != '\0')
{
if (!(a[c] == ' ' || a[c] == 9))
{
b[d] = a[c];
d++;
}
c++;
}
b[d]='\0';
}
int main()
{
int max_l=50;
char first[max_l], second[max_l], first_no_blanks[max_l], second_no_blanks[max_l];
printf("Enter first string:");
fgets(first, max_l, stdin);
printf("Enter second string:");
fgets(second, max_l, stdin);
for(int i=0; i<50; i++)
{
first[i]=tolower(first[i]);
second[i]=tolower(second[i]);
}
remove_blanks(first, first_no_blanks);
remove_blanks(second, second_no_blanks);
comparsion(first_no_blanks,second_no_blanks);
if(check(first_no_blanks, second_no_blanks)==1)
{
printf("Entered strings are anagrams.\n");
}
else
{
printf("Entered strings aren't anagrams.\n");
}
system("pause");
return 0;
}