This program is to take in a number of words, reverse them and compare the reverse word to the original and print how many times they differ by character for example racecar in reverse would differ 0 times and "toy" would differ twice... i know i am close. here is what i have.
Code:
#include<stdio.h>
#include<string.h>
int main(){
//declare variables and assign arrays for strings
char str[50];
char rev[50];
int k,change,n,i=-1,j=0;
//Inpute number of words
printf("How many words?\n");
scanf("%d", &n);
//input words
printf("Enter any %d words :\n",n);
for(i=0; i<n; i++){
scanf("%s",&str);
// take in string and reverse it by character
while(str[++i]!='\0');
while(i>=0)
rev[j++] = str[--i];
rev[j]='\0';
for(k=0; k<strlen(str); k++){
if(str[k] != rev[k])
change++;
}
//print reversed word
printf("The word %s differs from its reverse in %d places\n",str,k);
change=0;
}
return 0;
}