Thread: Struct (with pointer) to byte array

  1. #1
    Registered User
    Join Date
    Jan 2007

    Struct (with pointer) to byte array


    I have a struct that I need to convert to a byte(=char) array. Normally, I know how to do that using memcpy() but in this case the struct contains a pointer that I use to allocate memory dynamically elsewhere is my program.

    Something like:

    struct my_struct {
        int size;
        int num;
        int *list;
    } sb;
    and later on:
    sb.list = (int*)malloc(some_var);
    Is this even possible? If it is, what approach should I follow?


  2. #2
    "I Win!" by U. Lose vart's Avatar
    Join Date
    Oct 2006
    Rishon LeZion, Israel
    first convert struct contents without pointer, then convert memory pointed by the pointer
    To be or not to be == true

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Link List math
    By t014y in forum C Programming
    Replies: 17
    Last Post: 02-20-2009, 05:55 PM
  2. Array of struct pointers - Losing my mind
    By drucillica in forum C Programming
    Replies: 5
    Last Post: 11-12-2005, 10:50 PM
  3. Binary Search Trees Part III
    By Prelude in forum A Brief History of
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  4. Help with an Array
    By omalleys in forum C Programming
    Replies: 1
    Last Post: 07-01-2002, 08:31 AM
  5. Hi, could someone help me with arrays?
    By goodn in forum C Programming
    Replies: 20
    Last Post: 10-18-2001, 09:48 AM