fork download
  1. #include <stdio.h>
  2. #include <string.h>
  3. //#define length 100
  4.  
  5. int main(void){
  6. char text[100];
  7. int begin,middle,end=0;
  8. int i=0, choice = 0;
  9. int j=0;
  10. int count=0;
  11. int length =0;
  12. printf("Enter your word:\n ");
  13. for (i=0; i<100 && text[i-1]!='\n'; i++) scanf("%c", &text[i]);
  14. printf("%s",text);
  15. do{
  16. printf("\nEnter your choice: \n");
  17. printf(" 1. Display number of occurences of each letter\n");
  18. printf(" 2. Find whether the message is a palindrome\n");
  19. printf(" 3. Quit\n");
  20. scanf("%d", &choice);
  21. //added by me
  22. // printf (&choice);
  23. //end of added by me
  24. while (text[length] !='\0' ) length++;
  25.  
  26. end = length -1;
  27. middle= length/2;
  28.  
  29. for(begin = 0 ; begin < middle ; begin++ ){
  30. switch (choice){
  31. case 1:
  32. for(j=0; j < i; j++){
  33. if((text[j]>='a' && text[j]<='z') || (text[j]>='A' && text[j]<= 'Z')) count++;
  34. else continue;
  35. }
  36. break;
  37.  
  38. case 2:
  39. if (text [begin] != text[end] ) {
  40. printf("Not a palindrome.\n");
  41. break;
  42. }
  43. end--;
  44.  
  45. if( begin == middle )printf("Palindrome.\n");
  46. break;
  47. //added by me
  48. case 3:
  49. exit(0);
  50. //end of added by me
  51.  
  52. }
  53. }
  54. } while (choice != 3);
  55. return 0;
  56. }
Success #stdin #stdout 0s 1836KB
stdin
mom
2
3
stdout
Enter your word:
 mom
H�w�
Enter your choice: 
   1. Display number of occurences of each letter
   2. Find whether the message is a palindrome
   3. Quit
Not a palindrome.
Not a palindrome.
Not a palindrome.
Not a palindrome.

Enter your choice: 
   1. Display number of occurences of each letter
   2. Find whether the message is a palindrome
   3. Quit