title: C: send file to socket
body: <p>I`m trying to send binary file using socket.</p>
  
  <pre><code>        FILE *file;
          char *file_data;
          file = fopen(filepath, "rb");
  
          //Allocate memory
          file_data=(char *)malloc(fileLen+1);
  
          //Read file contents into buffer
          fread(file_data, fileLen, 1, file);
          fclose(file);
  
          sent = send(client, file_data, strlen(header)+fileLen, 0);
  </code></pre>
  
  <p>It works OK, but some files a too large and I want to read a part to buffer, send it, then read the second part, send it and so on.</p>
  
  <p>I tried to get parts using fread and fgets, but i failed =( How to do it correctly?</p>
  
  <p>UPD: the trouble was in reading incoming request from client. I didnt read it. If i do it, nothing bad happens</p>