hello,
i have created a program in c trying to check if two strings (size 30) give by the user are anagrams of each other but up till now i have the following code and can't find my way out ...
PS: in order not to have to give the words each time i have assign them in vars w1 & w2
the code is the following:
thanks
i have created a program in c trying to check if two strings (size 30) give by the user are anagrams of each other but up till now i have the following code and can't find my way out ...
PS: in order not to have to give the words each time i have assign them in vars w1 & w2
the code is the following:
#include <stdio.h> #include <string.h> int main() { char w1[30] = "daager", w2[30] = "garden", *p1=w1 ,*p2=w2; int countW1[30], counterW2[30]; int j=0, i=0,k=0, count=0; //elegxos an oi dio lexeis exoun to idio mikos. if (strlen(w1) == strlen(w2)){ printf("same size w1= %ld w2 = %ld!\nchecking chars...\n", strlen(w1),strlen(w2)); } //counting occurance of letters in first && second word for (i=0;i<strlen(w1);i++) { count = 0; for (k =0;k<strlen(w1);k++) { if (w1[i] == w1[k]) { countW1[i]++; } if (w2[i] == w2[k]) { counterW2[i]++; } if (w1[i] == w2[k] && countW1[i] == counterW2[k]) { printf("Brethike %c fores %d\n",w1[i], countW1[i]); } } printf("Char %c occurance is: %d times in first word\n",w1[i],countW1[i]); printf("Char %c occurance is: %d times in Second word\n",w2[i],counterW2[i]); } printf("\n\n"); //checking chars and occurances for (p1=w1; *p1!='\0'; *p1++) { for (p2=w2; *p2!='\0'; *p2++) { if (*p1 == *p2) { } } } return 0; }
thanks