Advertisement
Guest User

Untitled

a guest
May 25th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.30 KB | None | 0 0
  1. #include<stdio.h>
  2. #define TRUE 1
  3. #define FALSE 0
  4.  
  5.  
  6. int main(void)
  7. {
  8.     char phrase[101];
  9.    
  10.     printf("Enter phrase: ");
  11.     fgets(phrase, 101, stdin);
  12.  
  13.     printf("%s\n", phrase);
  14.     make_copy_of_string(phrase, phrase_copy);
  15.     keep_chars(phrase_copy);
  16.     conver_upper_to_lower(phrase_copy);
  17.  
  18. if(palindromeness(phrase_copy) == TRUE)
  19. {
  20.     printf("\nThe phrase:   %s\n is a palindrome.\n", phrase);
  21.  
  22. }else{
  23.     printf("\nThe phrase:   %s\n is not a palindrome.\n", phrase);
  24.  
  25. }
  26.     return 0;
  27.  
  28. }
  29. void make_copy_of_string(char str[], char str_copy[])
  30. {
  31.     int i=0;
  32.  
  33.     while(str[i] != '\n' && str[i] != '\0')
  34.     {
  35.         str_copy[i] = str[i];
  36.         i++;
  37.     }
  38.     str_copy[i] = '\0';
  39.     str[i] = '\0';
  40. }
  41. void keep_chars(char string[])
  42. {
  43.     int i=0, j=0;
  44.     while(string[i] != '\0')
  45.     {
  46.         if( ('A'<=string[i] && string[i] <= 'Z') || ('a'<= string[i] && string[i]<='z') )
  47.         {
  48.             string[j] = string[i];
  49.             i++;
  50.             j++;
  51.         }else{
  52.             i++;
  53.         }
  54.     } //end while loop
  55.     string[j] = '\0';
  56. }
  57. void convert_upper_to_lower_case(char string[])
  58. {
  59.     int i=0, j=0;
  60.     while(string[i] != '\0')
  61.     {
  62.         if( ('A'<= string[i] && string[i] <= 'Z') )
  63.         {
  64.             string[i]='\0';
  65.         }
  66.     }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement