TIP: Click on subject to list as thread! ANSI
echo: aust_c_here
to: Rowan_Crowe
from: Paul Wankadia
date: 1996-10-04 11:43:34
subject: Auto string-length determination

On 02 Oct 96, Rowan_Crowe wrote to Paul Wankadia --



 PW> I tried to automatically determine the maximum string length by using

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

 PW> because it is an array of char.  What am I doing wrong?

 R > I could be wrong, but sizeof(String) returns the number of chars. Are



I looked at the help for it a while back and it returns size_t, which is

supposedly the number of bytes...?



 R > you wanting the number of chars (elements), or number of bytes (an

 R > obscene word in portable C)?



The Max_Length of String -- the strlen().  Yes yes -- the number of elements,

if you insist :)



 R > What happens with the above line, does the compiler return an error,

 R > or are you getting unpredictable results?



Nope -- returns the sizeof() the pointer, according to everyone else who has

replied (I think).  Which appears to be 2.



 R > Assuming that the above expression is able to be evaluated at compile

 R > time, there should be no problems, as you'll get Max_Length =

 R > sizeof(String) / 1 (on a DOS platform).



Yeah -- but String is a pointer, as that line of code is in a function that

is passed a pointer to String <:(



 R > Cheers.



What's yours? :)



Chow.



Junyer Hakker.



--- PPoint 2.00

* Origin: Junyer's Workshop (3:640/772.3)
SEEN-BY: 50/99 620/243 623/630 640/201 206 216 217 222 230 238 254 297 305
SEEN-BY: 640/309 370 375 386 531 535 547 739 750 772 773 820 821 822 823 890
SEEN-BY: 640/895 711/409 410 413 430 808 809 932 934 712/515 713/888 714/906
SEEN-BY: 800/1
@PATH: 640/772 531 201 820 711/409 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™.