| TIP: Click on subject to list as thread! | ANSI |
| echo: | |
|---|---|
| to: | |
| from: | |
| date: | |
| subject: | Re: Auto string-length determination |
Hello Paul,
In a message dated 15 Oct 96 you wrote to me :
JM>> My suggestion would be to declare the function to return a char *
JM>> rather than an int. This way it doesn't matter how big the array is
JM>> since you're not copying to it.
PW> EH? Please explain what you mean in that last sentence (I don't quite
PW> get what you're trying to say) ...?
e.g.
declaration:
char *Get_Input( blah blah )
{
char *string;
/* code to get the string */
return (string);
}
usage:
#define STRING_SIZE 100
char s[STRING_SIZE];
strncpy(s, Get_Input(blah blah), STRING_SIZE);
s[STRING_SIZE]=0;
This will make sure that the user cannot input a string larger than what
you declared STRING_SIZE to be. It will also make the code a little
simpler to understand with less pointers in there to confuse you in six
months time when you come back to fix the bugs!
Josh Marshall FidoNet 3:640/201.14
Member TEAM AMIGA AmigaNet 41:400/869.14
... "Hehehe.. jokes on him. I'll be dead by then!" - Homer Simpson
--- Mail Manager 1.2x/p #1219
* Origin: It's rude to Point (3:640/201.14{at}fidonet)SEEN-BY: 633/267 270 @PATH: 640/201 201 820 711/409 808 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™.