TIP: Click on subject to list as thread! ANSI
echo: aust_c_here
to: andrew clarke
from: Rowan_Crowe
date: 1996-10-04 11:20:56
subject: Auto string-length determination

* andrew clarke writes to Rowan_Crowe, on Wednesday October 02 1996
   at 22:32:

 PW>>> int Max_Length = sizeof(String) / sizeof(char);

 ac> ...

 >> you'll get Max_Length = sizeof(String) / 1 (on a DOS platform).

 ac> sizeof(char) == 1 [byte] on all platforms.

Yup. I stand corrected (can we agree on 'clarified'? :) )

 ac> FWIW, if I'm reading this thread right I think the expression should
 ac> be

 ac>   size_t Max_Length = sizeof(String) - 1;

 ac> (In other words, the size of the entire array minus one byte for the
 ac> null terminator.)

But will this still work if the array is not in scope? What if it's passed
to a function as a pointer?

Cheers.

---
* Origin: Sensation BBS: Jelly-Bean support, Melbourne AUSTRALIA (3:635/727.1)
SEEN-BY: 50/99 620/243 623/630 632/349 635/503 544 727 728 670/218 711/409
SEEN-BY: 711/410 413 430 808 809 932 934 712/515 713/888 714/906 800/1
@PATH: 635/728 727 544 50/99 711/808 934

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.