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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Another sizeof() question

Status
Not open for further replies.

MinnisotaFreezing

Programmer
Jun 21, 2001
120
KR
Ok. If I go

TextOut(hdc, 0, 0, TEXT("Hello!"), sizeof("Hello!");

my string will come out the right length. But if I go

TCHAR * strBuff = "Hello!";
TextOut(hdc, 0, 0, strBuff, sizeof(strBuff));

it will not work because the pointer is smaller than the string, right, the reason to use a pointer. My question is, how can I get the length for TextOut dynamically using a pointer? That is

TextOut (hdc, 0, 0, strBuff, 6);

works with "Hello!" but if I want to change the string, I must then change the 6. I guess I'm looking for a Len() equivilent for C++.

Any help is greatly appriciated,

Thanks,

CJB
 
You can write:

TCHAR * strBuff = "Hello!";
TextOut(hdc, 0, 0, strBuff, sizeof(*strBuff));
(NOTICE THE *)

(this way you will not be forced to include string.h for strlen)

Hope this helps,s-)
Blessed is he who in the name of justice and good will, shepards the week through the valley of darknees...
 
sizeof(strBuff) will always return the size on an int in bytes(is always 4), which is the addreess of your string in RAM. John Fill
1c.bmp


ivfmd@mail.md
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top