how to find anagram without using string functions using
only loops in c programming

Answer Posted / csnr

#include<stdio.h>

int check(char [], char []);

main()
{
char a[100], b[100];
int flag;

printf("Enter first string\n");
gets(a);

printf("Enter second string\n");
gets(b);

flag = check(a, b);

if ( flag == 1 )
printf("\"%s\" and \"%s\" are anagrams.\n", a, b);
else
printf("\"%s\" and \"%s\" are not anagrams.\n", a, b);

return 0;
}

int check(char a[], char b[])
{
int first[26] = {0}, second[26] = {0}, c = 0;

while ( a[c] != '\0' )
{
first[a[c]-'a']++;
c++;
}

c = 0;

while ( b[c] != '\0' )
{
second[b[c]-'a']++;
c++;
}

for ( c = 0 ; c < 26 ; c++ )
{
if( first[c] != second[c] )
return 0;
}

return 1;
}

Is This Answer Correct ?    11 Yes 8 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Where does the name "C" come from, anyway?

900


How do you write a program which produces its own source code as output?

871


What is mean by data types in c?

790


Is c high or low level?

806


What is the difference between text and binary i/o?

820


How can I split up a string into whitespace-separated fields?

842


Is there a way to have non-constant case labels (i.e. Ranges or arbitrary expressions)?

866


what are non standard function in c

1684


Can we initialize extern variable in c?

898


What is hashing in c?

923


What are the 4 data types?

807


How can I prevent another program from modifying part of a file that I am modifying?

860


Whats s or c mean?

805


how to capitalise first letter of each word in a given string?

1705


How do you print an address?

1010