Pointer to Char

Hi everybody.

I have a little problem with pointers, i understand them but i dont know how to do this:


I have a pointer to an Address is there a way to save that address value (not the content but the actual address) into a char ?
No, at the very least the address would contain multiple characters.
The PTR of interest is of type DWORD* and where i want to store the address value is a char*, no hope?
Well, that's different. A char* is not a char.

Yes, you can store a pointer to a DWORD as a pointer to a char, if you cast it appropriately.

Of course, that won't change the nature of the data stored at that address. The data will still be appropriate for a DWORD, and attempting to use it as a char by de-referencing the char* will almost certainly cause you problems.

Why do you want to do this?

i have a program (i didnt create it but i have to test it) that has a function that returns a set of attributes from a given address.

something like this: "Attrib(VATY address)"

and the address needs to be a char* (well as i understand as VATY is defined as "typedef char* VATY;").

But for getting the address of interest i have a function that returns it to me but with a DWORD*. (DWORD *WPRPtr;).

I need to pass the WPRPtr (the address that it is pointing to) to the function that recieves the VATY.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include <iostream>
#include <string>
#include <cstdint>
#include <sstream>
#include <cstdio>

int main()
{
    double d = 7.8 ;
    double* pointer = &d ;

    // convert the address to a number and store the number
    std::uintptr_t value = std::uintptr_t(pointer) ;

    // convert the representation of address to a readable sequence of characters
    std::ostringstream stm ;
    stm << pointer ;
    std::string pointer_str = stm.str() ;

    char pointer_cstr[128] ;
    std::sprintf( pointer_cstr, "%p", (void*)pointer ) ;

    std::cout << pointer << ' ' << value << ' '
              << pointer_str << ' ' << pointer_cstr << '\n' ;
}

http://coliru.stacked-crooked.com/a/38d36da8adf94d5b
Topic archived. No new replies allowed.