0

does someone know a code in c that will send a complete ASCII file in 128 byte packets to another file? So The sender takes the ASCII file as input and sends a 128 byte packet on the data queue

2
Contributors
4
Replies
6
Views
7 Years
Discussion Span
Last Post by R3Slick
0

I'm confused about what you mean by send to a data file? Or data queue? Are you talking about sockets -- sending packets via sockets to another computer? Or are you talking about copying a file 128 bytes at a time ?

0

The second part of your question is what i want to do...Im not using sockets. So something like this will read the file. The arg[2] is the second argument in the command line so this will be the name of the file. But I need to convert that file into 128 packets or 122 byte packets so I can insert my checksum and a header to it too.

FILE * f1= fopen(arg[2],"r"); ///reads the file and that how far I am

Im confused myself. All i know is I have to read the file and convert it to packets then add a checksum and a header and then transfer it into a queue. So those packet will be in the queue and then I need to write a receive file that will read the packets and checksum them and write the results into a new file then i need to compare the original file with the file the receiver created to make sure they match...Im new to c and networking and this is way too hard.

1

open the file in binary mode then read it 128 bytes at a time

FILE* fp = fopen(arg[2],"rb");
char buf[128];
size_t nBytesRead;
while( (nBytesRead = fread(buf, 1, sizeof(buf), fp)) > 0)
{

}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.