Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <stdbool.h>
- #include <string.h>
- void push(char inputData[]);
- void pop();
- void printStack();
- char data[300][100];
- int current = 0;
- /*
- *
- */
- int main(int argc, char** argv) {
- FILE *file;
- if (argc > 1) {
- file = fopen(argv[1], "r");
- char line[256];
- while (fgets(line, sizeof (line), file)) {
- if (line[0] == '+') {
- memmove(line, line + 1, strlen(line));
- if (line[strlen(line) - 1] != NULL && line[strlen(line) - 1] == '\n') {
- line[strlen(line) - 1] = '\0';
- }
- push(line);
- printf("Added %s to the stack\n", line);
- } else if (line[0] == '-') {
- pop();
- }
- }
- }
- printStack();
- return (EXIT_SUCCESS);
- }
- void push(char inputData[]) {
- int i = 0;
- for(i = 0; i < strlen(inputData); i++) {
- data[current][i] = inputData[i];
- }
- current++;
- printf("\n Current Place: %d",current);
- }
- void pop() {
- printf("Pop: %s",data[current]);
- current--;
- }
- void printStack() {
- int i;
- printf("\n[");
- for(i = 0; i < current;i++) {
- printf("(%s)",data[i]);
- }
- printf("]");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement