Skip to content

Instantly share code, notes, and snippets.

@meldsza
Created August 22, 2018 15:55
Show Gist options
  • Save meldsza/28bcfd4d2f12187249b1e9f3d0814afb to your computer and use it in GitHub Desktop.
Save meldsza/28bcfd4d2f12187249b1e9f3d0814afb to your computer and use it in GitHub Desktop.
Palindrome dont ignore spacing
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#define MAX_SIZE 100
struct
{
int top;
char items[MAX_SIZE];
} typedef Stack;
char pop(Stack* s)
{
if(s->top == -1)
return 0;
return s->items[s->top--] ;
}
void push(Stack* s, char item)
{
s->items[++s->top] = item;
}
int main()
{
char orginal_string[MAX_SIZE] = {0}, final_string[MAX_SIZE] = {0};
char *temp;
Stack s;
s.top = -1;
puts("Enter a string");
gets((char*)orginal_string);
if(strlen(orginal_string) == 0){
puts("Enter valid string");
return 0;
}
temp = orginal_string;
while(*temp != 0)
{
push(&s,*temp);
temp++;
}
temp = final_string;
while((*temp = pop(&s))){
temp++;
}
*(++temp) = 0;
printf("Reverse of given string is\n%s\n",(char*)final_string);
if( strcmp(orginal_string, final_string) == 0)
puts("String is a palindrome");
else
puts("String is not a palindrome");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment