TIP: Click on subject to list as thread! ANSI
echo: aust_c_here
to: Paul Wankadia
from: Joshua Marshall
date: 1996-10-21 20:18:42
subject: Re: Auto string-length determinatio

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: 50/99 620/243 623/630 640/201 201 206 217 222 230 238 254 297 305
SEEN-BY: 640/309 370 375 386 531 820 821 822 823 890 895 690/660 711/409 410
SEEN-BY: 711/413 430 808 809 932 934 712/515 713/317 714/906 800/1
@PATH: 711/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™.