Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

grab chars adress

Status
Not open for further replies.

homeless

Programmer
Nov 6, 2001
20
CH
i try to save the adress of single char from an char*
something like this will not work

[sub]
static int* m_pPagePosition;
char* &pBuffer;
m_pPagePosition = reinterpret_cast<int*>(&pBuffer); // grab address
[/sub]
 
The type of pBuffer var is char*& - reference to pointer to char. But references must be initialized in C++. So you can't compile the snippet above!
If you want to save an address of a char you need char* (pointer to char) variable. You can't save it as int* (pointer to int) because of it may be invalid pointer to int (int alignment).
Try to explain your need, please. The snippet above has no sense...
 
THX ArkM

needed the position into the string, i don't know what a nonsense i've post:

Code:
char *ptr = text + 4; // Zeichen 'o'
int offset = ptr - text;

done
 
OK, pointer arith... Also pay attention to wonderful RTL functions from <cstring>: strchr, strcspn, strpbrk...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top