TIP: Click on subject to list as thread! ANSI
echo: aust_c_here
to: Joshua Marshall
from: Paul Edwards
date: 1996-10-29 08:39:14
subject: Re: Auto string-length determinatio

JM> usage:
JM> #define STRING_SIZE 100

JM> char s[STRING_SIZE];
JM> strncpy(s, Get_Input(blah blah), STRING_SIZE);
JM> s[STRING_SIZE]=0;

JM> This will make sure that the user cannot input a string larger than what 
JM> you declared STRING_SIZE to be.  It will also make the code a little 
JM> simpler to understand with less pointers in there to confuse you in six 
JM> months time when you come back to fix the bugs!

I think it's better, where possible, to do a:

strncpy(s, dfdfdfdfdfdfd, sizeof s);

so that if you need to make s of size APPLE_SIZE instead of STRING_SIZE,
you don't need to change your code.  BFN.  Paul.
@EOT:

---
* Origin: X (3:711/934.9)
SEEN-BY: 633/267 270
@PATH: 711/934 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™.