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. string[]={'a','b',' ','b','a'};
  52. int l=strlen(string);i=0;
  53. while(i<l)
  54. {
  55. push(string[i]);
  56. i++;
  57. }
  58. i=0;
  59. char string2[size];
  60. while(i<l)
  61. {
  62. string2[i]=(char)pop();
  63. i++;
  64. }
  65. printf("\nReversed text=%s",string2);
  66. if(strcmp(string,string2)==0)printf("\nText is palindrome\n");
  67. else printf("\nText is not palindrome\n");
  68. return 0;
  69. }
Compilation error #stdin compilation error #stdout 0s 9432KB
stdin
5
compilation info
prog.c:9:1: warning: data definition has no type or storage class
 top=-1;
 ^~~
prog.c:9:1: warning: type defaults to ‘int’ in declaration of ‘top’ [-Wimplicit-int]
prog.c: In function ‘main’:
prog.c:51:12: error: expected expression before ‘]’ token
     string[]={'a','b',' ','b','a'};
            ^
prog.c:37:23: warning: unused variable ‘x’ [-Wunused-variable]
     char string[size],x;
                       ^
stdout
Standard output is empty