Unsure how to correct my code here, regardless of what I input it always reads an anagram.
#include<stdio.h>
#include<string.h>
int main() {
int flag = 0;
int counter1 = {0, 0, 0, 0};
int counter2 = {0, 0, 0, 0};
char s1 = “abcd”;
char s2 = “abcd”;
for (int i = 0; i < strlen(s1); i++){
if (s1[i] = ‘a’){
counter1[0]++;
}
else if (s1[i] = ‘b’){
counter1[1]++;
}
else if (s1[i] = ‘c’){
counter1[2]++;
}
else if (s1[i] = ‘d’){
counter1[3]++;
}
else
counter1;
break;
}
for (int i = 0; i < strlen(s2); i++) {
if (s2[i] = ‘a’) {
counter2[0]++;
}
else if (s2[i] = ‘b’) {
counter2[1]++;
}
else if (s2[i] = ‘c’) {
counter2[2]++;
}
else if (s2[i] = ‘d’) {
counter2[3]++;
}
else
counter2;
break;
}
for (int i = 0; i < 4; i++) {
if (counter1 || counter2) {
flag++;
printf (“Not an anagram!\n%d”, flag);
break;
}
else
printf(“Anagram!”);
break;
}
}
2 posts - 2 participants