hey,
can anyone help me write up a function to remove space, semicolons, etc?
ty.
can anyone help me write up a function to remove space, semicolons, etc?
ty.
char j = string[i];
if((j >= 'a' && j <= 'z') || (j >= 'A' && j <= 'Z') || j == ' ' || (j >= '0' && j <= '9')) {
str += string[i];
}
char j = string[i];
if(isalpha(j) || isspace(j) || isdigit(j)) {
str += string[i];
}
char j = string[i];
if((j >= 'a' && j <= 'z') || (j >= 'A' && j <= 'Z') || j == ' ' || (j >= '0' && j <= '9')) {
str += string[i];
}
char j = string[i];
if(isalpha(j) || isspace(j) || isdigit(j)) {
str += string[i];
}
/*Write a program of palindrome using stack [implement stack using array]:
Note: Punctuation, Capitalization, and Spaces are ignored. For Example- Poor dan is in a droop.
Date : February 21,2014 */
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <stdbool.h>
bool is_palindrome(const char* s)
{
int i = 0;
int j = strlen(s) - 1;
while(j >= 0)
{
if(!isalpha(s[i]))
{
++i;
}
else if(!isalpha(s[j]))
{
--j;
}
else if(tolower(s[i]) != tolower(s[j]))
{
return false;
}
++i;
--j;
}
return true;
}
void printme(const char* s)
{
printf(" \" %s\" ",s);
if(is_palindrome(s))
{
printf(" IS a palindrome! \n");
}
else
{
printf(" IS NOT a palindrome! \n");
}
}
int main()
{
char s[] = "kajak";
char s2[] = "Poor Dan is in a droop";
char s3[] = "not a palindrome";
printme(s);
printme(s2);
printme(s3);
return 0;
}
Comment