I am going to write a very simple program on protocolling in C.
So, in a frame, it should contains a header, packets and a trailer.
In header I planned to put only the sequence of a file, a sequence
of packets of that file and lastly, the length of that packet.
I was wondering how should I represent the header?
Should I represent it with an integer (int) or character (char) or
hexadecimal or something else (any suggestion)?
Lets say there are 3 files all together which have been splitted into a lot of packets.
I was planning to represent the first sequence of a file with
a letter 'a' because character took only 1 bytes and letter 'a'
again to represent the first sequence of packets of that file.
Thus, to represent the second order of packets of that file it
should be a letter 'b'. If I choose alphabet from 'a' to 'z', wouldn't
it be limited to 26 packets only? If I choose 2 letters to represent
the sequence of packets, I have 676 combination and this will consume 2 bytes (any suggestion to lower down the size or maybe use other thing to represent header)?
unsigned long fileNumber, packetNumber, packetLength;
Now, that'd give you ~4 billion files, packets, and file length in bytes. If you want short packet, and I imagine you do, the packet length may want to be an unsigned short integer. This would give you 64K packet size max. If you want very small packets, use an unsigned char.
You could use an unsigned short for file number. Shrug. It depends how you're going to work with this. Do you anticipate vast numbers of files being transfered ever?
> I have 676 combination and this will consume 2 bytes
So choose to represent this as an unsigned short int, which is also 2 bytes, and can represent 65536 different values.
We concatenate a string with a string by using strcat or strncat.
But how do we concatenate a string with an interger??
Please give me some example.