Pushok

Palindromes identifier (exclude digits)

Apr 17th, 2011
438
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.89 KB | None | 0 0
  1. #include "stdio.h"
  2. #include "stdlib.h"
  3. #include "conio.h"
  4. #include "iostream"
  5.  
  6. void delchar(char* str, char ch)
  7. {
  8.     if(str == 0 || *str == 0) return;
  9.  
  10.     char* ptr = str;
  11.     while(*ptr != 0) if(*ptr == ch) break; else ptr++;
  12.  
  13.     while(1)
  14.     {
  15.         char c = *ptr;
  16.         *ptr = ptr[1];
  17.         ptr[1] = c;
  18.         if(*ptr == 0) return; else ptr++;
  19.     }
  20. }
  21.  
  22. char* _strrev_(const char* str)
  23. {
  24.     char str_[1024];
  25.     str_[strlen(str)] = 0;
  26.  
  27.     for(int i=strlen(str)-1, j=0;i>=0;i--,j++)
  28.         str_[i] = str[j];
  29.    
  30.     return str_;
  31. }
  32.  
  33. int main()
  34. {
  35.     char str[1024], strptr[1024];
  36.     printf("Input palindhrom: \n");
  37.     gets(str);
  38.  
  39.     for(int i=0;i<strlen(str);i++)
  40.     {
  41.         if(str[i] == 0) break;
  42.         if(isupper(str[i]) || isdigit(str[i]))
  43.             delchar(str, str[i]);
  44.     }
  45.  
  46.     printf((strcmp(_strrev_(str), str) == 0 ? "Yes, this is palindromes:\n %s\n %s" : "No, this is not palindromes:\n %s\n %s"), str, _strrev_(str));
  47.  
  48.     getch();
  49. }
Advertisement
Add Comment
Please, Sign In to add comment