The folllowing code is giving wrong output?

if INPUT is : hello beautiful
world
OUTPUT should be : hello beautiful

but its not happening…why?

#include
using namespace std;
int main() {
char c,ch[40];
cin>>c;
for(int i=0;c!=’\n’;++i){
ch[i]=c;
cin>>c;
}
cout<<ch;
return 0;
}

i didn’t understand the question
please tell the question and
paste your code at http://ide.codingblocks.com/
and then share the link of code generated after saving the file

@asaurabh_26
if INPUT is : (copy paste following in input file)

hello beautiful
world

OUTPUT should be : (expected output according to me)

hello beautiful

but its not happening…why?

#include
using namespace std;
int main() {
char c,ch[40];
cin>>c;
for(int i=0;c!=’\n’;++i){
ch[i]=c;
cin>>c;
}
cout<<ch;
return 0;
}

instead of cin>>c
use c=cin.get()
this is because
cin ignores the whitespace (’\n’,spaces, etc)

correct code

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.