TIP: Click on subject to list as thread! ANSI
echo: aust_c_here
to: Paul Wankadia
from: Roy McNeill
date: 1996-10-02 19:36:18
subject: Auto string-length determination

Hello Paul



 PW> My input routine requires that the programmer pass (as a parameter) the

 PW> maximum length of the string :



 PW> int Get_Input(char *, int, Idle_Ptr = Idle, int = 0, char * =
"\x00");

 PW>                       ~~~



 PW> after they have declared the variable with a certain length

 PW> char String[100] = "";



 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?



You can't ask for the 100 figure that was written in the char

String[100] line, because a C program doesn't remember that number

once it's allocated the ram for String. (This is one of the reasons

C is fast.) To get the max length, you'll need another parameter to

your function, or a global variable, or a global #define constant.



Exactly why do you need the max length? Why can't you work with

the length of the current string?



Cheers



--- PPoint 1.88


* Origin: Silicon Heaven (3:711/934.16)
SEEN-BY: 711/808 934
@PATH: 711/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™.