0

so heres a snippet of my code:

cout << "enter keyphrase: \n";
	cin >> nextchar;

	while(nextchar != '.')
	{
		isalreadyin = 0;
	for (int i=0; i<counter; i++)
	{
		if (key[i] == nextchar)
			isalreadyin = 1;
	}
		
		if(isalreadyin ==0)
		{
			key[counter]=nextchar;
			counter ++;
		}

		cin >> nextchar;

	}

at the moment i have '.' as my terminiating character. but i want new line to be it. But i cannot get it to work. ive tried '\n' and that dont work. i also tried the ascii value but that dont work so i kinda came to a dead end. So could anybody give me ideas on why it wont work?

p.s the nextchar is a char so could it be that char variable cannot accept '\n'

Edited by lethal.b: n/a

5
Contributors
6
Replies
8
Views
6 Years
Discussion Span
Last Post by WaltP
0

Why not read the line in as a std::string using getline() (which will stop at the newline) and do the processing of the characters afterwards?

0

Why not read the line in as a std::string using getline() (which will stop at the newline) and do the processing of the characters afterwards?

i tried that before but for college i have to use visual c++ 6.0 and there is a bug when using getline which reads in extra characters. there is a fix on microsofts website but i cant fix it at college as i cant edit the programs files

0

How does using '\n' not work? It won't compile, crashes if you hit enter or pressing enter does not terminate the loop?

0

How does using '\n' not work? It won't compile, crashes if you hit enter or pressing enter does not terminate the loop?

it compiles fine but just doesn't terminate the loop

0

Then you aren't reading a \n.

After reading the character, immediately display it's binary value cout << (int) nextchar; If you don't see the value of '\n', you aren't reading it.

This article has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.