Pushok icon

Palindromes identifier (exclude digits)

Pushok | PRO | 04/17/11 12:05:20 PM UTC | 0 ⭐ | 426 👁️ | Never ⏰ | []
C |

890 B

|

None

|

0 👍

/

0 👎

#include "stdio.h"
#include "stdlib.h"
#include "conio.h"
#include "iostream"
 
void delchar(char* str, char ch)
{
    if(str == 0 || *str == 0) return;
 
    char* ptr = str;
    while(*ptr != 0) if(*ptr == ch) break; else ptr++;
 
    while(1)
    {
        char c = *ptr;
        *ptr = ptr[1];
        ptr[1] = c;
        if(*ptr == 0) return; else ptr++;
    }
}
 
char* _strrev_(const char* str)
{
    char str_[1024];
    str_[strlen(str)] = 0;
 
    for(int i=strlen(str)-1, j=0;i>=0;i--,j++)
        str_[i] = str[j];
    
    return str_;
}
 
int main()
{
    char str[1024], strptr[1024];
    printf("Input palindhrom: \n");
    gets(str);
 
    for(int i=0;i<strlen(str);i++)
    {
        if(str[i] == 0) break;
        if(isupper(str[i]) || isdigit(str[i]))
            delchar(str, str[i]);
    }
 
    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));
 
    getch();
}

Comments