Hi, I'm a complete new C++ newbie, I'm trying to graduate from batch scripting to real programming, and in doing so, also trying to convert some of my programs. This is of course long and laborious as I wade through the tutorials.
I'm sorry therefore if any of my questions seem obvious but as of yet I have very little idea what I am doing, so let me thank you in advance for your patience and help.
I'm trying to write some code to help me input single addresses, which will eventually develop into a program which will let me input an address and print it to a local printer. I'm struggling with the input though.
Here is my code so far, and what is wrong below.
Thanks
mikeyp
Code:
int main()
{
cout<<"This program prints single address labels input by the user.\n\n";
// address enter function
// str length is 23 as 22+terminating.char "\0"
char address[7][23];
cout<<"Enter the address to be printed.\n";
for ( int x = 0; x < 7; x++ ) {
//Address input here
cout<<"Line "<< x + 1 <<": ";
cin.getline ( address[x], 23, '\n' );
};
cout<<"\n\nYour address was: \n\n";
for ( int x = 0; x < 7; x++ ) {
//Address output here
cout<<address[x]<<endl;
};
cin.get();
I *need* the address to be 22 chars wide max. If I enter fewer chars, everything is fine (example 1) If I enter something which needs truncating, everything goes horribly wrong (example 2). It doesn't allow me to enter the latter lines, and rushes through till it finishes.
Example 1
Code:
This program prints single address labels input by the user.
Enter the address to be printed.
Line 1: Arthur Bond
Line 2: 34 Tepe Avenue
Line 3: Great Malvern
Line 4: Some Postcode
Line 5:
Line 6:
Line 7:
Your address was:
Arthur Bond
34 Tepe Avenue
Great Malvern
Some Postcode
Process returned 0 (0x0) execution time : 67.236 s
Press any key to continue.
Example 2
Code:
This program prints single address labels input by the user.
Enter the address to be printed.
Line 1: Sir Arthur Reginald Debug
Line 2: Line 3: Line 4: Line 5: Line 6: Line 7:
Your address was:
Sir Arthur Reginald De
Process returned 0 (0x0) execution time : 19.938 s
Press any key to continue.