TIP: Click on subject to list as thread! ANSI
echo: aust_c_here
to: Paul Wankadia
from: Paul Edwards
date: 1996-09-30 23:27:34
subject: Auto string-length determination

PW> My input routine requires that the programmer pass (as a parameter) the
PW> maximum length of the string :

PW> after they have declared the variable with a certain length (e.g. like this 
PW> :

PW> char String[100] = "";

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

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

sizeof(char) is useless - it will ALWAYS be 1.

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

Apart from that (it does no harm), what is actually wrong?  I can't see any
reason why the above code wouldn't set Max_Length to 100. Of course, the
statement above needs to have String[100] in scope, not char *String (which
would return 2/4/etc).  BFN.  Paul. 
@EOT:

---
* Origin: X (3:711/934.9)

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™.