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

   Either there is some error I'm stupidly overlooking or some quirk in this
program code.  If I took out all references to the fifth item in the 
tructure
it would show the two characters for the State at the end and finish.  But, 
s
it is you can see that following the two character State name this program
will immediately continue with the characters of the zip code and then also
put in the zip code on the next line.  
   I'm compiling on a 486/133 with Borland version 3.0 compiler.  What is
causing this?
   Many thanks in advance.  I know my face will be red when I learn why.  
 //DATABASE.CPP - playing with char data items
#include 
#include 
#include 
#include 
class database
{
    private:
        char name[20];
        char address[20];
        char city[10];
        char state[2];
        char zip[10];
    public:
        void getdata(char n[], char a[], char c[], char s[], char z[])
        {
            strcpy(name,n);
            strcpy(address,a);
            strcpy(city,c);
            strcpy(state,s);
            strcpy(zip,z);
        }
        void showdata()
        {
            cout << "Name =    " << name << '\n';
            cout << "Address = " << address << '\n';
            cout << "City =    " << city    << '\n';
            cout << "State =   " << state   << '\n';
            cout << "ZipCode = " << zip     << '\n';
        }
};
main()
{
    clrscr();
    database d;
    d.getdata("Sam Jones","SomeStreet", "SomeCity", "SS", "33333-2222" );
    d.showdata();
    return 0;
}
Sincerely, 
                                     Frank
                                                                              
                                                       
--- PPoint 2.05
---------------
* Origin: Maybe in 5,000 years - frankmas@juno.com (1:396/45.12)

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