#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!!