title: C — How would I make my stack completely dynamic?
body: <p>Currently my code uses a stack and pushes a user entered string into the stack one by one. However I would like to make it dynamic, what would I malloc/realloc, I know I'm missing something completely obvious but I guess I have tunnel vision... help?</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #define MAXSIZE 100
  char a [MAXSIZE];
  char * p = a;
  int top = -1;
  
  void push ( char n )
  {
      if ( top == 99)
      {
          printf( "stack overflow");
          return;
      }
      top+=1;
      a[top] = n;
  }
  
  
  /*  Function to delete an element from the stack */
  void pop(){
      if(top == -1)
          printf("Stack is Empty");
      else
          top-=1;
  
  }
  
  char *inputString(FILE* fp, size_t size){
      //The size is extended by the input with the value of the provisional
      char *str;
      int ch;
      size_t len = 0;
      str = realloc(NULL, sizeof(char)*size);//size is start size
      if(!str)return str;
      while(EOF!=(ch=fgetc(fp)) &amp;&amp; ch != '\n'){
          str[len++]=ch;
          if(len==size){
              str = realloc(str, sizeof(char)*(size+=16));
              if(!str)return str;
          }
      }
      str[len++]='\0';
  
      return realloc(str, sizeof(char)*len);
  }
  int balanced (char * m){
      int size = sizeof(m);
      int i, j;
      for (i=0; i&lt;=size; ++i){
          push(m[i]);
      }
  }
  int main(void){
      char *m;
  
      printf("input string : ");
      m = inputString(stdin, 10);
      printf("%s\n", m);
      balanced(m);
      int i;
      for (i=0;i&lt;=sizeof(a);++i){
          printf("\n%c", a[i]);
      }
      free(m);
      return 0;
  }
  </code></pre>