Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <cs50.h>
- #include <string.h>
- #include <ctype.h>
- #define MAX 100
- int top;
- /*PUSH FUNCTION*/
- void push (char stack[], char* item)
- {
- ++top;
- stack [top] = *item;
- }
- char pop (char stack[])
- {
- char ret;
- if (top == -1)
- {
- ret = 0;
- }
- else
- {
- ret = stack [top];
- --top;
- }
- return ret;
- }
- int main(void)
- {
- //char stack[MAX];
- char word[MAX];
- top = -1;
- string s = GetString();
- int len = strlen(s);
- int x = 1;
- if (len < 0 || len > MAX)
- {
- return 1;
- }
- for(int i = 0, j = 0; i <= len; i++)
- {
- if (!isalnum(s[i]))
- {
- while (x <= j)
- {
- s[x] = pop(word);
- printf("%c", s[x]);
- x++;
- }
- x = 0;
- j = 0;
- }
- else
- {
- push(word, &s[i]);
- j++;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement