CHARACTER ARRAY- ACCEPTING WHITE SPACE CHARACTERS

#include<iostream.h>
#include<conio.h>
void main()
{clrscr();
char name[15];
cout<<"\nEnter your name.\n";
for(int i=0;i<15;++i)
{cin>>name[i];}
cout<<"\n\n";
for(i=0;i<15;++i)
{cout<<name[i];}

getch();
}

********
This is a simple program to take input of characters in a name and that will definitely include a space. But when I enter a space, the program rejects it takes another value for that storage place.

But I need the program to accept white space characters.
** I know, this can be done by using many other ways like using the string array or a built-in function, but my teacher has asked us to use the basic logic and not to use built-in features.

OP wrote:
... my teacher has asked us to use the basic logic and not to use built-in features.


Erm, then you shouldn't be using the stream operators at all if I understand the asinine requirements. Ever notice how they don't work without the 'iostream' header? Anyway, your problem is that the input stream operator skips whitespace by default. You alter this behavior with 'std::noskipws' in C++: http://www.cplusplus.com/reference/ios/noskipws/ . I think it works in C as well but I'm not 100% sure...
Topic archived. No new replies allowed.