TIP: Click on subject to list as thread! ANSI
echo: aust_c_here
to: Paul Wankadia
from: Paul Edwards
date: 1996-10-06 14:29:42
subject: Auto string-length determination

PW> I tried to automatically determine the maximum string length by using :
PW> int Max_Length = sizeof(String) / sizeof(char);

BTW, as far as I'm aware, you're meant to go "sizeof String" for
a variable, and "sizeof(char)" for a data type.

PW> int Max_Length = sizeof(String);

PW> is supposed to be in a function that is called and passed a char * to 
PW> String, which (I am told) will then make Max_Length the sizeof() a char * 
PW> !!!

PW> That is correct -- I am getting 2, not 100.  How do I get the correct 
PW> length with just a char * ???

The short story is you can't, because the function may be external, and how
did you expect the compiler to magically know the length? It can only know
the length if you give it that information, either as an extra parameter,
or padding the variable out so you can do a strlen(), or specify the size
in the prototype, or use a #define, or use a STRING structure of your own,
that contains both a length and a character pointer.  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™.