fork download
  1. #include<stdio.h>
  2. #include<string.h>
  3. #define SIZE 30
  4. struct stack
  5. {
  6. int top;
  7. char st[SIZE];
  8. }s;
  9. top=-1;
  10.  
  11. void push(char x)
  12. {
  13. if(s.top==SIZE-1)printf("Stack is full");
  14. else s.st[++s.top]=x;
  15. }
  16.  
  17. int pop()
  18. {
  19. if(s.top==-1)
  20. {
  21. printf("Stack is empty");
  22. return (int)'\0';
  23. }
  24. else
  25. {
  26. char x=s.st[s.top];
  27. s.top--;
  28. return (int)x;
  29. }
  30. }
  31.  
  32. int main()
  33. {
  34. int size,i=0;
  35. printf("Enter size:");
  36. scanf("%d",&size);
  37. char string[size],x;
  38. printf("Enter string:");
  39. //scanf("%s",string);
  40. /*for(i=0;string[i]!='\0';i++)
  41.   {
  42.   scanf("%c",string[i]);
  43.   }*/
  44. //gets(string);
  45. while(x!='\0')
  46. {
  47. x=getchar();
  48. string[i]=x;
  49. i++;
  50. }
  51. int l=strlen(string);i=0;
  52. while(i<l)
  53. {
  54. push(string[i]);
  55. i++;
  56. }
  57. i=0;
  58. char string2[size];
  59. while(i<l)
  60. {
  61. string2[i]=(char)pop();
  62. i++;
  63. }
  64. printf("\nReversed text=%s",string2);
  65. if(strcmp(string,string2)==0)printf("\nText is palindrome\n");
  66. else printf("\nText is not palindrome\n");
  67. return 0;
  68. }
Success #stdin #stdout 0s 9416KB
stdin
3
aba
stdout
Enter size:Enter string:
Reversed text=
Text is not palindrome