TIP: Click on subject to list as thread! ANSI
echo: aust_c_here
to: Paul Wankadia
from: Frank Adam
date: 1996-10-02 09:17:00
subject: Auto string-length deter

G'Day Paul,
 
-=> Quoting Paul Wankadia to All <=-


 PW> after they have declared the variable with a certain length (e.g. like
 PW> this : 
 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?
If the string was declared locally yes it would work, but..
The function only gets the pointer to the string, it has no idea about the 
length of it, all it knows is that it'll have to put the strng it gathers
up in the function into the address provided.  
So sizeof() will return the length of the pointer. 
Perhaps if the string is global it may also work, but i didn't try or even
said that !.:)

PS: if portability is not an issue look at heapwalk in Borland, or go 
2 or 4 bytes (i forget) back from the pointer and you'll find the 
alloced block size somewhere, it only seems to work with the Borland RTL..
                                                     
  L8r Frank (fadam{at}ozemail.com.au).
                               
___ Blue Wave/DOS v2.21

--- Gash
* Origin: The Software Parlour (3:635/544)
SEEN-BY: 50/99 620/243 623/630 632/349 635/503 544 727 711/409 410 413 430
SEEN-BY: 711/808 809 932 934 712/515 713/888 714/906 800/1
@PATH: 635/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™.