Advertisement
anta40

Tumpukan

Oct 24th, 2012
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.52 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. char* stack[10];
  6.  
  7. void push(char foo[]) {
  8.     int counter;
  9.     for (counter = 0; counter < sizeof(stack); counter++) {
  10.         if (stack[counter] != NULL) {
  11.             strcpy(stack[counter], foo);
  12.             break;
  13.         }
  14.     }
  15. }
  16.  
  17. int main(int argc, const char *argv[]) {
  18.     int i;
  19.    
  20.     for (i = 0; i < 10; i++) stack[i] = malloc(20 * sizeof(char));
  21.     for (i=1; i < argc; i++)  push(argv[i]);
  22.  
  23.     printf("%s\n",stack[0]);
  24.     printf("%s\n",stack[1]);
  25.     printf("%s\n",stack[2]);
  26.     return 0;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement