memcpy() problem

Discussion in 'C Programming' started by danu, Oct 23, 2006.

  1. danu

    danu Guest

    Basically I'm trying to do here is put the uint32_t seq_num into the
    first 4 bytes of the buf. But every time I do this, it wouldn't get
    copied in to the buf at all. Can anyone point out the problem. Thanks a
    lot.

    char buf[packet_size];
    uint32_t seq_num = 0;
    uint32_t packet_num = 0;

    while((nread = read(fd, buf+8, packet_size-8)) > 0) {
    packet_num++;
    seq_num = htonl(packet_num); /* htonl: used to convert the
    actual packet_num into network numbers*/
    memcpy(buf, &seq_num, 4);
    .....
    .....
    }
     
    danu, Oct 23, 2006
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ninan Thomas
    Replies:
    3
    Views:
    450
    Kevin Goodsell
    Aug 22, 2003
  2. Bren
    Replies:
    8
    Views:
    2,072
    Stephen Howe
    Sep 4, 2003
  3. Paul Schouten
    Replies:
    2
    Views:
    2,450
    Vladimir Khvostov
    Jan 3, 2005
  4. ronny

    memcpy problem

    ronny, Feb 13, 2005, in forum: C++
    Replies:
    2
    Views:
    4,723
    ronny
    Feb 13, 2005
  5. Ninan Thomas
    Replies:
    3
    Views:
    2,013
    Kevin Goodsell
    Aug 22, 2003
Loading...

Share This Page