title: c - Pointer's content disappears after usage
body: <p>I have this piece of code where <code>complexp</code> is a pointer to a <code>struct</code> that represents a complex number. The first <code>printf</code> command works just fine and <code>complexp</code>'s content is printed. However,  the second <code>printf</code> does not work properly and prints <code>0</code> twice (which is not correct).</p>
  
  <p>There is no code between these two lines.</p>
  
  <pre><code>int main()
      {
          ComplexP  complexp =  (ComplexP) malloc(sizeof(ComplexP));
          complexp = fromCharFunc(s);
  
          printf("complexp: real: %f, imaginary: %f\n", complexp-&gt;real, complexp-&gt;imaginary);
  
           printf("1complexp: real: %f, imaginary: %f\n", complexp-&gt;real, complexp-&gt;imaginary);
  
      return 0;
      }
   typedef struct Complex {
     double real;
     double imaginary;
   } Complex;
  
  typedef struct Complex* ComplexP;
  ComplexP fromCharFunc(char * s)
  {
      if(s == NULL)
      {
          return NULL;
      }
  
  
  char* sreal;
  char* simaginary;
  double real;
  double imaginary;
  
  char str [DEFAULT_SIZE];
  
  strcpy(str, s);
  sreal = strtok(str, REALL_PART_DELIMITER);
  
  simaginary = strtok(NULL, IMAGINARY_PART_DELIMITER);
  
  int len1 = strlen(sreal) + strlen(simaginary);
  int len2 = strlen(s) - strlen(IMAGINARY_PART_DELIMITER);
  
  int diff = len1 == len2 ? 0 : 1;
  
  
  if(diff)
  {
      return NULL;
  }
  
  
  if(verifyIsNumber(sreal))
  {
      real = atof(sreal);
  }
  else
  {
      return NULL;
  }
  
  if(verifyIsNumber(simaginary))
  {
      imaginary = atof(simaginary);
  }
  else
  {
      return NULL;
  }
  
  Complex complex = {real, imaginary};
  ComplexP complexp = &amp;complex;
  
  return complexp;
  
  }
  /**
   * @brief determines whether a string represents a number
   * @param char *s poiter to a string
   * #retrun 0 if not a number, 1 if is a number
   */
  int verifyIsNumber(char *s)
  {
  char c;
  int i = 0;
  while( *(s+i) != '\0')
  {
      c = *(s+i);
      if ((c &gt;= MIN_DIGIT &amp;&amp; c &lt;= MAX_DIGIT) || c == POINT || c == MINUS)
          i++;
      else
      {
          return 0;
      }
  }
  
  return 1;
  
  }
  </code></pre>