I made this program, I get the address, name and user work. Then it puts it all on one line and prints that line. (I know there are better ways to do this)
char str[600];
char adrs[200];
char name[10];
char wrk[200];
cout<<"Enter your name and press ENTER: ";
cin.getline(name,10);
cout<<"\nEnter your adress and press ENTER:";
cin.getline(adrs,200);
cout<<"\nEnter your workplace and press ENTER:";
cin.getline(wrk,200);
strcpy(str,"My name is ");
strcat(str,name);
strcat(str,"\nand i live at ");
strcat(str,adrs);
strcat(str, "\nI also work at ");
strcat(str, wrk); strcat(str, "\n\n");
cout<<str<<endl;
Here, when I write a name that exceeds 10 characters, the program executes the first 9 characters entered by the user, as I expected, but after that it skips all the next ones cin.getline()that are in the program, and goes to the output strand terminates the program.
Why is this happening and how to fix it?
source
share