Advertisement

02.03.2008 at 07:54PM PST, ID: 23133931
[x]
Attachment Details

Best way to read from stdin

Asked by maloriopolium in C++ Programming Language, SSH / Telnet Software

Tags: C++

Hi,

I would like to know if there is a better method to read from stdin than the current one I have.

This is what I currently use:


But the problem is, some very long strings seems to get truncated from time to time and I don't receive the entire string being sent.
Can someone please help me identify what could be the problem?

A bit of background:
My program listens to input on stdin. It is called by Microsoft telnet server because MS telnet server is responsible for listening to incoming telnet connections. So everytime something is picked up by MS telnet server, MS telnet server then calls my program which receives the string as stdin. So either my code to read from stdin is not very well written, or could it be that there is a problem with MS telnet server passing me a truncated string?

I need help on this urgently.

Thanks very much.Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
string str = "";
CStdStringA bufs = "";
 
while(true)
{
         fflush(stdin);
 
	while(((ch = getchar()) != '\r'))
	{
 
		if(ch == '\n')
		{
			break;
		}
		else
		{
			bufs.append(1, (char) ch);
			i++;
		}
	}
         str = bufs;
         bufs = ""; //Reset the string to empty
 
          .....//Code to handle the str.....
}
 
 
Loading Advertisement...
 
[+][-]02.03.2008 at 08:49PM PST, ID: 20811996

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: C++ Programming Language, SSH / Telnet Software
Tags: C++
Sign Up Now!
Solution Provided By: jkr
Participating Experts: 4
Solution Grade: A
 
 
[+][-]02.03.2008 at 09:26PM PST, ID: 20812133

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]02.03.2008 at 09:33PM PST, ID: 20812163

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]02.03.2008 at 09:34PM PST, ID: 20812165

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]02.03.2008 at 09:35PM PST, ID: 20812174

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]02.04.2008 at 01:00AM PST, ID: 20812817

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]02.04.2008 at 01:01AM PST, ID: 20812826

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]02.04.2008 at 01:26AM PST, ID: 20812947

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]02.04.2008 at 02:21AM PST, ID: 20813143

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]02.04.2008 at 02:25AM PST, ID: 20813160

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]02.04.2008 at 02:26AM PST, ID: 20813164

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]02.04.2008 at 06:24PM PST, ID: 20820153

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]02.04.2008 at 07:21PM PST, ID: 20820390

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.29.2008 at 03:41PM PDT, ID: 21466848

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.10.2008 at 05:48PM PDT, ID: 21541119

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 7-day free trial to view this Administrative Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628