Thread: Any suggestion?

  1. #1

    Smile Any suggestion?

    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)?

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    struct protocolHeader
    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?


  3. #3

    Question unsigned intergers?

    > 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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Platform suggestion
    By weefolk in forum A Brief History of
    Replies: 10
    Last Post: 01-31-2006, 08:10 AM
  2. Replies: 12
    Last Post: 05-14-2003, 01:00 AM
  3. any suggestion - pointer, strtok, function etc
    By Unregistered in forum C Programming
    Replies: 1
    Last Post: 01-13-2002, 02:04 AM
  4. Need a suggestion on a school project..
    By Screwz Luse in forum C Programming
    Replies: 5
    Last Post: 11-27-2001, 02:58 AM