Thread: void pointers

  1. #1
    Software Developer jverkoey's Avatar
    Join Date
    Feb 2003
    University of Waterloo

    void pointers

    ok, begin long question:

    here's what i want/need to do. begin pseudocode:

    //Now, say i have a function that accepts a void*, an unsigned int, and another unsigned int.........::
    void GrabData(void* GrabbedData, unsigned int beg, unsigned int Size)
    // Now, we want to be able to pass any type of variable to "GrabbedData", specify a begin positon, and the size of the variable in bytes.
    // Once we've passed that, the code should do this:
    Look in the FileData (which is a separate void* variable elsewhere that has already been given data) and set the "get" position to "beg"
    grab <Size> data and set it to <GrabbedData>
    end pseudocode

    now, say we have an unsigned int and a file that has about 8 bytes in it. Say the file was like so: (in hex)


    now, say we set beg to 2, and pass the unsigned int with a sizeof(unsigned int) for the "Size" variable
    when you call the function, it should get that data from the "FileData" variable, and since it's a pointer, automatically change the value of the passed variable.

    in a sense this works the same was as fread, whereas you pass a pointer to a variable, the size in bytes, and the number of variables to get (in case you have an array or whatever). that is the same thing i want to achieve, except i need to do it with a void* variable (FileData) that already has data in it (which was read from a file)

    this way i can read from an internal variable and not have to worry about constantly accessing the file itself.

    If anyone knows how to do this (or just knows how fread works), please post here.

    Thank you

    *begins searching in google for documentation on how fread works.......*
    *returns from google search without finding much.......*
    Last edited by jverkoey; 08-13-2003 at 05:20 PM.

  2. #2
    Just because ygfperson's Avatar
    Join Date
    Jan 2002
    size_t fread (void *buffer, size_t width, size_t count, FILE *file_pointer)
    buffer is your destination buffer, where you want the data to go.
    width is how big your unit of data is. (If you use a char* in the first argument, it'll be one byte.)
    count is how many units you want
    the file pointer is the file you're reading from.

    fread returns the amount of units it could successfully read.

  3. #3
    Software Developer jverkoey's Avatar
    Join Date
    Feb 2003
    University of Waterloo
    i already know how to use that, i use it to read all the data in right away! lol

    what i need to do is read the data from the void* that already has data it is pointing at.....

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Inserting a swf file in a windows application
    By face_master in forum Windows Programming
    Replies: 12
    Last Post: 05-03-2009, 11:29 AM
  2. Seg Fault in Compare Function
    By tytelizgal in forum C Programming
    Replies: 1
    Last Post: 10-25-2008, 03:06 PM
  3. i cannot see the mouse arrow
    By peachchentao in forum C Programming
    Replies: 6
    Last Post: 12-10-2006, 04:14 AM
  4. Quack! It doesn't work! >.<
    By *Michelle* in forum C++ Programming
    Replies: 8
    Last Post: 03-02-2003, 12:26 AM
  5. oh me oh my hash maps up the wazoo
    By DarkDays in forum C++ Programming
    Replies: 5
    Last Post: 11-30-2001, 12:54 PM