TIP: Click on subject to list as thread! ANSI
echo: aust_c_here
to: Roy McNeill
from: Paul Wankadia
date: 1996-10-04 11:41:50
subject: Auto string-length determination

On 02 Oct 96, Roy McNeill wrote to Paul Wankadia --



 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?

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

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

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

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

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



Oh.  What if I use strdup() locally to create another string?



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

 RM> the length of the current string?



Eh?  I'm writing my own custom Get_Input() function and I'd like to cut down

the number of parameters that it takes -- especially the one that passes the

length of String...  The length may vary from program to program, so I have

to account for that :)



Chow.



Junyer Hakker.



--- PPoint 2.00

* Origin: Junyer's Workshop (3:640/772.3)
SEEN-BY: 50/99 620/243 623/630 640/201 206 216 217 222 230 238 254 297 305
SEEN-BY: 640/309 370 375 386 531 535 547 739 750 772 773 820 821 822 823 890
SEEN-BY: 640/895 711/409 410 413 430 808 809 932 934 712/515 713/888 714/906
SEEN-BY: 800/1
@PATH: 640/772 531 201 820 711/409 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™.