Reading user input into c-string

Hi everyone,
I just started learning about c-strings, but I'm having a little trouble. For my class, we're not allowed to use strings, so I'm reliant on c-strings only for this purpose. I found a bit of code that I thought would do what I want, but it's not working:

I'm trying to read user input into a char array like this:

1
2
3
4
5
6
const int MAX_CHAR = 101;
char name[MAX_CHAR];

cin.getline(name, MAX_CHAR, '\n');

cout << name;


It lets me type the word and I don't get any errors, but the cout >> name line doesn't print the word read into name. What am I doing wrong?

Thanks for your help.
Last edited on
Incorrect structure for cout.(you used one which is used with cin)


correct way
cout<<name;
Last edited on
Oops... that was just a typo on here. It's right in my program, but it's still not working.
Well it works for me.
only problem was this.
Maybe you mistyped something else in program.
I think!!!!!

cin.ignore();// to delete auxiliary storage
cin.getline(name, MAX_CHAR, '\n')
puts(name);

this is a string so you can use puts(char *s); .......I think so......I dont check so I dont know this right ...
Topic archived. No new replies allowed.