cin not reading

i have to write a program that will display all characters selected in the input sentance. problem i have is it just skips the input for the character

1
2
3
4
5
6
7
8
9

	char sentance[500];
	char character[10];

	cout << "enter a sentance ";
	cin.get( sentance[500] );
        cout << "enter a character to display all selected characters ";
        cin >> character[10];
        cout<< "you selected "<<character;
Last edited on
cin.get( sentance[500] );
Reads a single character in sentance[500] (which is out of bounds and lead to UB).

Mayby you want overloads 3 or 4 from here:
http://en.cppreference.com/w/cpp/io/basic_istream/get
Or just
http://en.cppreference.com/w/cpp/io/basic_istream/getline

Solution to your next problem: http://stackoverflow.com/questions/21567291/why-does-stdgetline-skip-input-after-a-formatted-extraction
I'd say .. type it this way..

1
2
3
4
5
6
7
8
char *sentance;
char *character;

cout<<"Enter a sentance";
cin>>sentance;
cout<<"Enter a character to display all selected characters";
cin>>character;
cout<<"You selected"<<character;



maybe this works..
Check out
Well the right spelling to sentance is - sentence
Last edited on
closed account (E0p9LyTq)
maybe this works..


Did you actually test it? I did. It doesn't work.

Read what MiiNiPaa wrote.

Using uninitialized pointers may compile, but the resulting exe from either VC++2015 and TDM-GCC 4.9.2 crashes. The memory is not allocated.
@FurryGuy

Umm.. Sorry if I'm wrong .. I'm just new to this programming field and this Forum ...
So I was just trying to solve the problem of the above guy..I'm sorry if I was wrong..
@Swapnil2000
you code doesnt work "cin>>sentence" will not read past any (space) characters.
thanks for input
@learningcplusplus898
Ah ok
Topic archived. No new replies allowed.