#include <stdio.h>
#include <string.h>

void word_to_lower(char buff[]) {
  int start = 'A';
  int stop = 'Z';
  int difference = 32;
  for (int i = 0; i<strlen(buff);i++) {
    if (buff[i] >= start && buff[i] <= stop) {
      buff[i]+= difference;
    }
  }
}

void strrev (char rline[])
{
  int i,j;
  char temp;

  i = 0;
  j = (strlen(rline)) -1;

  while(i < j)
  {
    temp = rline[i];
    rline[i] = rline[j];
    rline[j] = temp;
    ++i;
    --j;
  }
}

int palindrome (char buff[]) {
  char possible[100];
  char reversed[100];

  strcpy(possible,buff);
  strcpy(reversed,buff);
  strrev(reversed);
  word_to_lower(possible);
  word_to_lower(reversed);

  if (strcmp(possible,reversed) == 0) {
    return 1;
  } else {
    return 0;
  }
}


int main () {
  
  char word_to_check [100];

  printf("Write a word to check for palindrominess: ");
  scanf("%99s",word_to_check);
  if (palindrome(word_to_check)) {
    printf("%s is a palindrome\n", word_to_check);
  } else {
    printf("%s is NOT a palindrome\n", word_to_check);
  }
}

  
