TIP: Click on subject to list as thread! ANSI
echo: os2prog
to: Joe Kelch
from: Jonathan de Boyne Pollard
date: 1995-04-13 08:44:02
subject: How Long Is A Piece Of..

JK>
  > Only problem is, I don't see how this is going to help you in case of a str
  > that you simply don't know in advance what size it will be.  It's a Catch-2
  > either you must get the string first [gets(string)] and then
  > malloc(sizeof(string)), which isn't really going to help, or you malloc a s
  > for your string first, then gets(string) and hope it fits, which isn't any
  > better than char StrName[some integer].
JK>

  If this is a real concern, use a loop with istream::get(), that
  dynamically allocates a return buffer as it goes along until it reads
  a newline character.  For best results, considering the way that most
  C++ run-time heaps are mannaged, reallocate the return buffer 16 bytes
  bigger every 16 bytes (or use a larger power of two).

  You must remember to destroy the buffer after use, of course.

  > JdeBP <
___
 X MegaMail 2.10 #0:
--- Maximus/2 2.02
* Origin: DoNoR/2,Woking UK (44-1483-722344) (2:440/4)
SEEN-BY: 105/42 620/243 711/401 409 410 413 430 807 808 809 934 955 712/407
SEEN-BY: 712/515 628 704 713/888 800/1 7877/2809
@PATH: 440/4 141/209 270/101 105/103 42 712/515 711/808 809 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™.