I need a help

#include "stdafx.h"
#include <iostream>
#include <cstring>

using namespace std;


int main()
{
char str[600];
char name[100];
char addr[200];
char work[200];

cout << "Enter name and press Enter.: ";
cin.getline(name, 10);
cout << "\nEnter address and rpess Enter. ";
cin.getline(addr, 20);
cout << "\nEnter workplace and press Enter: ";
cin.getline(work, 20);

strcpy(str, "\nMy name is ");
strncat(str, name, 599-strlen(str));
strcat(str, ", I live at ");
strncat(str, addr, 599-strlen(str));
strcat(str, ",\nand I work at ");
strncat(str, work, 599-strlen(str));
strcat(str, ".");

cout << str << endl;

return 0;
}


////////////
When I enter my name on this line (cin.getline(name, 10);) over the size(10), next cin.getline functions dont work.

For instance
if i enter "Hello Helllo Hello Helllo"

The output is like this:

Enter address and rpess Enter.
Enter workplace and press Enter:
My name is Hello Hel, I live at ,
and I work at .

Other cin.getline fuctions are skipped.

what's wrong!!
1. Use code tags to show code. Like this:

[code]
1
2
//See?  Nice-looking code.
//Plus it gets line numbers! 
[/code]

2. Your first getline() call restricts the input to 10 characters. You probably meant 100.
3. Since you are using getline(), you need to enter each piece of information as a separate sentence; you must hit the ENTER key after you type each piece.
Topic archived. No new replies allowed.