title: Copying unknown length buffer to a fixed size buffer in C
body: <p>How can we copy an unknown size buffer into a fixed buffer in c?</p>
  
  <p>For one of my functions, I'm trying to copy an unknown size buffer into a fixed buffer (of size 1024 bytes). The fixed size buffer is declared in a struct (Later I'll need to send all the content of the struct at once). I am unsure which function would be best to solve this issue. </p>
  
  <p>I will send the struct buffer (ex_buffer) and reset the values in the struct buffer (ex_buffer); Then I need to store the next 1024 bytes from the unknown size buffer (buffer) into the fixed buffer (ex_buffer) and so on.</p>
  
  <p>I've attached a small snippet of a general code for example purposes.</p>
  
  <pre><code> struct example {
        char ex_buffer[1024];
   }
  
   int main (int argv, char *argv[]){
        char *buffer = realloc(NULL, sizeof(char)*1024);
        FILE *example = fopen(file,"r");
  
        fseek(example, 0L, SEEK_END);
        //we compute the size of the file and stores it in a variable called "ex_size"
  
        fread(buffer, sizeof(char), ex_size, example);
        fclose(example);
  
        //Now we want to copy the 1024 bytes from the buffer (buffer) into the struct buffer (ex_buffer)
        While( "some counter" &lt; "# of bytes read"){
              //copy the 1024 bytes into struct buffer
              //Do something with the struct buffer, clear it
              //Move onto the next 1024 bytes in the buffer (ex_buffer)
              //Increment the counter
        }
  
   }
  </code></pre>