title: c function with array do not return value
body: <p>I wrote the following c-code. </p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  char *read_from_file()
  {
  
      FILE *ptr_file;
      char buf[22];
      char buf_old[sizeof(buf)];
      char candata_needed[4]; 
          ptr_file =fopen("/home/pi/probe.txt","r");
          if (!ptr_file){
              fclose(ptr_file);
              return 1;
          }
          if (fgets(buf,sizeof(buf), ptr_file)!=NULL){
  
              if(memcmp(buf, buf_old, sizeof(buf)))
              {
                  memcpy(candata_needed, buf + 17, sizeof(buf));              
                  memcpy(buf_old, buf, sizeof(buf));
              }
          }       
          fclose(ptr_file);    
     return (candata_needed);        
  }    
  
  int main()
  {
          char *candata;
          int i;
  
      while(1){
          printf("stape 1\n");        
          candata=read_from_file()
          for(i=0; i&lt;4; i++)
          {
              candata[i] = *(candata + i);
          }
          printf("candata: %s\n", candata); 
      }
          free(candata);
          return 0;
  }
  </code></pre>
  
  <p>The Function should read a file and store the content(the content is a 22 Hex number) in an Array. From the 22 hex number, i only need 4, so i stored the 4 hex number in a Array(candata_needed). 
  So i want to get the stored 4 hex number from the function in a main-function a pointer. I tried with <code>malloc</code> but i became repeatedly an error  <code>double free or corruption (fasttop)</code>. With the pointer nothing appears. 
  Can anybody help please?   </p>