title: Sending files via TCP/IP
body: <p>i'm trying to send a file via TCP/IP using a C++ program on windows. The send and the reception works fine. but in the received file two commas appear after every 40 character. If I send for example :</p>
  
  <pre><code>123456789
  123456789
  123456789
  123456789
  123456789
  123456789
  23456789
  123456789
  123456789
  123456789
  123456789
  123456789
  123456789
  123456789
  </code></pre>
  
  <p>The recepted file is :</p>
  
  <pre><code>123456789
  123456789
  123456789
  123456789
  123456789
  „123456789
  123456789
  123456789
  123456789
  123456789
  „123456789
  123456789
  123456789
  123456789
  </code></pre>
  
  <p>Here is the server code for sending a file :</p>
  
  <pre><code>static int send_client_file(SOCKET sock, char *Sbuffer){
  
  int n = 0;
  char* f_name = "send.txt";
  //char* f_name = "server.c";
  
  cout &lt;&lt; endl &lt;&lt; "Waiting for the client message" &lt;&lt; endl;
  FILE *fp = fopen(f_name, "r");
  if (fp == NULL)
  {
      cout &lt;&lt; "ERROR : File " &lt;&lt; f_name &lt;&lt; " not found ";
      perror("fopen()");
      exit(errno);
  }
  
  //bzero(Sbuffer, 50); // on vide le buffer d'envoie
  memset(Sbuffer, 0, 50);
  while((n = fread(Sbuffer, sizeof(char), 50, fp)) &gt; 0)
  {
      if((n = send(sock, Sbuffer, strlen(Sbuffer), 0)) &lt; 0)
      {
          perror("send()");
          exit(errno);
      }
      memset(Sbuffer, 0, 50);
  }
  
  cout &lt;&lt; "file sent" &lt;&lt; endl;
  
  return n;
  }
  </code></pre>
  
  <p>And here is the client code to receive it : </p>
  
  <pre><code>int static recv_server_file(SOCKET sock, char *buffer){
  
  int n = 0;
  int m = 0;
  
  cout &lt;&lt; endl &lt;&lt; "Receiving file from the server..." &lt;&lt; endl;
  char* f_name = "receive.txt";
  FILE *fp = fopen(f_name, "a");
  if (fp == NULL)
  {
      cout &lt;&lt; "ERROR : File " &lt;&lt; f_name &lt;&lt; "not found " &lt;&lt; endl;
      perror("fopen()");
      exit(errno);
  }
  
  else {
  
  while(n = recv(sock, buffer, Rbuffer_size, 0))
  {
      if (n &lt; 0)
      {
          perror("recv()");
          exit(errno);
      }
      m = fwrite(buffer, sizeof(char), n, fp);
  
      if(m &lt; n)
      {
          cout &lt;&lt; "File write failed." &lt;&lt; endl;
          break;
      }
  
      break;
      memset(buffer, '/0', Rbuffer_size);
  }
  cout &lt;&lt; "ok!" &lt;&lt; endl;
  
  fclose(fp);
  }
  cout &lt;&lt; "The received data is : " &lt;&lt; buffer &lt;&lt; endl ;
  
  return m;
  
  }
  </code></pre>
  
  <p>As you can see, there is ",," which appears in the recepted file. Any idea of how to resolve this ?</p>