| TIP: Click on subject to list as thread! | ANSI |
| echo: | |
|---|---|
| to: | |
| from: | |
| date: | |
| subject: | Auto string-length determination |
On 06 Oct 96, Paul Edwards wrote to Paul Wankadia -- PW> I tried to automatically determine the maximum string length by using : PW> int Max_Length = sizeof(String) / sizeof(char); PE> BTW, as far as I'm aware, you're meant to go "sizeof String" for a PE> variable, and "sizeof(char)" for a data type. "sizeof String" ??? Are you SURE??? No one else has pointed that out! PW> is supposed to be in a function that is called and passed a char * to PW> That is correct -- I am getting 2, not 100. How do I get the correct PW> length with just a char * ??? PE> The short story is you can't, because the function may be external, It is intended to be external. PE> and how did you expect the compiler to magically know the length? It Damn. Oh well -- back to passing the strlen() then :) PE> can only know the length if you give it that information, either as an PE> extra parameter, or padding the variable out so you can do a strlen(), Extra parameter, I reckon. I can't rely on "padding" and passing a struct with String inside it is MUCH too bothersome for me (and for anyone who might want to use my function :) PE> or specify the size in the prototype, or use a #define, or use a PE> STRING structure of your own, that contains both a length and a PE> character pointer. BFN. Paul. None of the above would really cut it. I'll go with the parameter, unless I decide to move completely to OOP (in which case I'll make a struct :) 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 690/660 711/409 410 413 430 808 809 932 934 712/515 713/888 SEEN-BY: 714/906 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™.