title: Reading from file in C using fread
body: <p>I'm learning how to read content from a file in C. And I manage to scrape through the following code.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  
  void read_content(FILE *file) {
    char *x = malloc(20);
    // read first 20 char
    int read = fread(x,sizeof(char),20,file);
    if (read != 20) {
       printf("Read could not happen\n");
     }
    else {
        printf("the content read is %s",x);
    }
    free(x);
    return; 
  }
  
  int main(int argc,char *argv[]) {
  
    FILE *fp; 
    fp = fopen("test.txt","w+");
    read_content(fp);
    fclose(fp);
    return 0;
  }
  </code></pre>
  
  <p>But for some reason (which I'm not able to understand) I see the <code>read</code> bytes count as <code>0</code>.</p>