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

* Paul Wankadia writes to All, on Sunday September 29 1996
   at 09:13:

 PW> char String[100] = "";

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

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

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

I could be wrong, but sizeof(String) returns the number of chars. Are you
wanting the number of chars (elements), or number of bytes (an obscene word
in portable C)?

What happens with the above line, does the compiler return an error, or are
you getting unpredictable results?

Assuming that the above expression is able to be evaluated at compile time,
there should be no problems, as you'll get Max_Length = sizeof(String) / 1
(on a DOS platform).

Cheers.

---
* Origin: Sensation BBS: Jelly-Bean support, Melbourne AUSTRALIA (3:635/728.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™.