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

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:
    652
    Kevin Goodsell
    Aug 22, 2003
  2. Bren
    Replies:
    8
    Views:
    2,331
    Stephen Howe
    Sep 4, 2003
  3. Paul Schouten
    Replies:
    2
    Views:
    2,597
    Vladimir Khvostov
    Jan 3, 2005
  4. ronny

    memcpy problem

    ronny, Feb 13, 2005, in forum: C++
    Replies:
    2
    Views:
    4,944
    ronny
    Feb 13, 2005
  5. Ninan Thomas
    Replies:
    3
    Views:
    2,554
    Kevin Goodsell
    Aug 22, 2003
  6. =?ISO-8859-1?Q?Martin_J=F8rgensen?=

    problem with memcpy and pointers/arrays confusion - again

    =?ISO-8859-1?Q?Martin_J=F8rgensen?=, Mar 9, 2006, in forum: C Programming
    Replies:
    39
    Views:
    1,575
    Ben Pfaff
    Mar 21, 2006
  7. danu

    memcpy() problem

    danu, Oct 23, 2006, in forum: C Programming
    Replies:
    6
    Views:
    517
    J. J. Farrell
    Oct 23, 2006
  8. jack

    memcpy problem

    jack, Feb 25, 2011, in forum: C Programming
    Replies:
    2
    Views:
    931
    Jens Thoms Toerring
    Feb 25, 2011
Loading...