| TIP: Click on subject to list as thread! | ANSI |
| echo: | |
|---|---|
| to: | |
| from: | |
| date: | |
| subject: | Auto string-length deter |
G'Day Roy,
-=> Quoting Roy Mcneill to Paul Wankadia <=-
PW> Uh huh... I've decided to stay with passing the maximum length to the
PW> function. Thanks :)
RM> One thing still eludes me: why does your function want to know the
See ? Told you, you didn't understand him, you'd have to have that sort of
"beginner's blood" in you. :-)
RM> max length, rather than the actual length? The only reason I can
RM> think of is that your function could change the string, making it
RM> longer, and needs to know when to stop. Is this the case?
Suppose that could be a reason, but there is no reason why the calling
function couldn't do the allocation itself if need be.
IMHO..he wanted to limit the chars input by the user, and have full
control of it at the keyboard level(or just after), not just copying
maxlen bytes back from..let's say fgets().
Something like this..
int GetString(char *buffer)
{
int key = 0,max = 0;
char *buf = buffer;
MaxBufLen = MagicBufsAllocSize(buffer);
/*
you know this one don't you ? :) It would return the number of bytes
allocated to buffer.
*/
while(!(key = getkey()))
{
switch(key)
{
case 13 : *buf[max] = '\0';return max;
default :
if(max < MaxBufLen && isascii(key))
{
max++;
*buf++ = key; /* if smaller than maxlen update buf */
putchar(key); /* and only then put the char to screen */
} /* else cursor does not move and buf remains unchanged */
}
}
return 0;
}
It's a very much simplified, but anyway you get the idea...
In either case i have and Paul has also found that passing maxlen is
still preferred, for other reasons.
L8r Frank (fadam{at}ozemail.com.au).
___ Blue Wave/DOS v2.21
---
* Origin: Melbourne PC User Group BBS (3:632/309)SEEN-BY: 633/267 270 @PATH: 632/309 107 635/503 50/99 635/728 633/267 |
|
| 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™.