TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: JAMIE KOWINSKY
from: JONATHAN ROBERTS
date: 1997-10-09 20:17:00
subject: Char[] Strings

RE: Char[] Strings
BY: Jamie Kowinsky to All on Wed Oct 08 1997 08:06 pm
 > If the char array is 5 elemets and someone types in a huge string what 
ill
 > happen?  I'm assuming since cin doesnt know the size of my array that it 
wil
 > just write all thoese bytes over whatever happens to be in memory after 
he
 > array of chars.
       Actually, the PC will lock up.  You should use something like:
cin.get(stringvar, 30);  // string var is your variable and 30 is the max 
                         // chars
 > Also, I need a bit of a refresher course with char array strings, One 
oint
 > can't quite remember is the max length of a string that can be entered 
nto
 > arary of a given size, is it size-1? For example, if an array has 3 
elements
 > (0-3) I cannot store "the" as there will be no null character, but "hi" is 
o
 > as it would be "Hi"+nullch (3 elements)
       No.  char mystring[3] will accept "the" fine.
Jonathan
--- Synchronet+SBBSecho v1.25
---------------
* Origin: The Caverns BBS - 504.831.2825 (1:396/20)

SOURCE: echomail via exec-pc

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™.