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'

what is nextchar defined as?

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?

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

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

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

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.