TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: FRANK MASINGILL
from: GEORGE WHITE
date: 1997-10-10 08:39:00
subject: Error showing data

Hi Frank,
FM>   Either there is some error I'm stupidly overlooking or some quirk in 
this
FM>program code.  If I took out all references to the fifth item in the 
structu
FM>it would show the two characters for the State at the end and finish.  
ut,
FM>it is you can see that following the two character State name this program
FM>will immediately continue with the characters of the zip code and then 
lso
FM>put in the zip code on the next line.
You're overlooking something...
FM>   I'm compiling on a 486/133 with Borland version 3.0 compiler.  What is
FM>causing this?
You've not left space for the string terminator, a NULL character (== 0)
FM>   Many thanks in advance.  I know my face will be red when I learn why.
It's probably the commonest mistake programmers make comeing to C/C++
from any other language.
 most details to save bandwidth
FM>        char state[2];
Reserve 2 characters for state.
FM>            strcpy(state,s);
Copy state - but it's 2 characters + a terminator below...
FM>    d.getdata("Sam Jones","SomeStreet", "SomeCity", "SS", "33333-2222" );
In C/C++ you have to declare strings to be one longer than the max
string length they are to hold.
George
 * SLMR 2.1a * User, n. technical term used by computer pros. See Idiot.
--- Maximus/2 3.01
---------------
* Origin: DoNoR/2,Woking UK (44-1483-717905) (2:440/4)

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