I have two strings, I want to know if they are equal to each other. However the strings character-order has been randomized. Also certain characters may have been swapped out with a wildcard operator (*). I'm using this for Anagram detection.
In this case, I'm trying to get the anagram program I have to say that ab** is an anagram of abba. Right now it can tell if its an anagram if it is literally an anagram like abba and bbaa. Now I'm trying to figure out how to implement wildcard *'s and I have no idea where to start, please help!
What i have so far:
#include <stdlib.h>
#include <stdio.h>
#include <stdbool.h>
#define SIZE 5
bool areAnagram(char *str1, char *str2)
{
int count[SIZE] = {0};
int i = 0;
for (i = 0; str1[i] && str2[i]; i++)
{
count[str1[i]]++;
count[str2[i]]--;
}
if (str1[i] || str2[i])
{
return false;
}
for (i = 0; i < SIZE; i++)
{
if (count[i])
{
return false;
}
}
return true;
}
int main()
{
char str1[SIZE], str2[SIZE];
FILE *finput;
finput = fopen("input.txt", "r");
fscanf(finput, "%s %s", str1, str2);
printf("%s\n", str1);
printf("%s\n", str2);
if(areAnagram(str1, str2))
{
printf("THEY ARE ANAGRAMS\n");
}
else
{
printf("THEY AREN'T ANAGRAMS\n");
}
}