Reading files - Buffer size
I am having problems reading a file into packet sized buffers.
Each packet is 1024 bytes in size, and is being sent through a socket.
Below, rep = number of packets, dwSize is the acutal size in bytes of the file.
As you can imagine the small packets work fine, as it is only a max of 1 packet big, which means i can read the actual file size stright into the packet buffer.
rep = dwSize / 1024;
// Small Packet (File Size < 1024)
fread(szBuff, 1, dwSize, pFile);
send(theSocket, szBuff, dwSize, 0);
// Larger Packets (File Size Bigger than 1024)
for(int i = 0; i < rep; i++)
fread(szBuff, 1, dwSize / 1024 * i, pFile);
send(theSocket, szBuff, 114, 0);
However the larger packets im having problems with, say i have a 3000 byte file, there will be 2.92 packets to send.
Now the problem is that im not sure how i can set fread() to read in the full packet size if its (in this case) 2 times, then the final time only read in the remaining .92 section of the full packet.
I have tried doing it 3 times complete 1024 packets then null terminating the string but it just fills it with random memory characters and crap. The sizeof and strlen functions on the buffer dont help me much either as strlen says its 4 characters big possible becasue the file is encrypted.
Any ideas on how i can make a packet reader loop cycle that works on files over 1024 bytes? Baring in mind i have the Packet number (i) full file size (dwSize) and total number of packets (rep).