title: How to Dynamically allocate the array size of your char variable based on the length of the user's input?
body: <p>I need to let the user enter his first name and store it in an array <code>char</code> and the size of this array is dynamically located depend on user name that he entered.</p>
  
  <p>This is my code :</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  void main()
  {
      static int size = 5 ;
      printf("please Enter Your First Name..\n");
  
      char* p = (char*)malloc(size*sizeof(char));
  
      for(int i = 0 ; i &lt;= sizeof(p) ; i++)
      {
          if(sizeof(p)+1 == size )
          {
              p = (char*)realloc(p,2*size*sizeof(char));
              size = sizeof(p);
          }
          else
          {
              scanf("%c",&amp;p[i]);
          }
  
      }
      for(int i = 0 ; i &lt;=size ; i++)
      {
          printf("%s",*(p+i));
      }
  
  free(p);
  
  }
  </code></pre>
  
  <p>I give the array a first size of 5 <code>char</code>, then if the user name length is more that this size, Its realloc in heap a double size of the size, </p>
  
  <p>and I make a condition  <code>if(sizeof(p)+1 == size )</code> because <code>sizeof(p) = 4</code> , so I need 5 = 5 so thats I put <code>sizeof(p)+1</code>. </p>
  
  <p>But my code is not working. Why?</p>