Advertisement
Guest User

reverse

a guest
Jul 29th, 2016
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <cs50.h>
  3. #include <string.h>
  4. #include <ctype.h>
  5.  
  6. #define MAX 100
  7. int top;
  8.  
  9. /*PUSH FUNCTION*/
  10. void push (char stack[], char* item)
  11. {  
  12.     ++top;
  13.     stack [top] = *item;
  14. }
  15.  
  16. char pop (char stack[])
  17. {  
  18.     char ret;
  19.     if (top == -1)
  20.     {  
  21.         ret = 0;
  22.     }
  23.     else
  24.     {  
  25.         ret = stack [top];
  26.         --top;
  27.     }
  28. return ret;
  29. }
  30.  
  31. int main(void)
  32. {
  33.     //char stack[MAX];
  34.     char word[MAX];
  35.     top = -1;
  36.     string s = GetString();
  37.     int len = strlen(s);
  38.    
  39.     int x = 1;
  40.     if (len < 0 || len > MAX)
  41.     {
  42.         return 1;
  43.     }
  44.     for(int i = 0, j = 0; i <= len; i++)
  45.     {
  46.         if (!isalnum(s[i]))
  47.         {
  48.             while (x <= j)
  49.             {
  50.                 s[x] = pop(word);
  51.                 printf("%c", s[x]);
  52.                 x++;
  53.             }
  54.             x = 0;
  55.             j = 0;
  56.         }
  57.         else
  58.         {
  59.             push(word, &s[i]);
  60.             j++;
  61.         }
  62.  
  63.     }
  64.  
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement