Board index » cppbuilder » Questions about use of scanf / getchar() instructions in Borland C++

Questions about use of scanf / getchar() instructions in Borland C++


2006-08-02 09:16:20 AM
cppbuilder96
I need to be able to display an "R", followed by inputing a decimal numberv within a logical program loop without entering a
caraige return ("\n") I would like the loop to repeat itself by entering a whitespace character (newline, tab or space), but exit the loop when I hit the enter key, then start again. The following shows the routine as I now have it:
printf("\n\nEnter resistance number\n");
for (i= 0; i < n1; i++)
{
printf("\nRow %d, : \n", i+1);
for (j= 0; j < maxsize04; j++)
{
rws1 = 30;
printf("R");
scanf("%u,%c",&rws1,&s1);
while ((rws1 < 0) || (rws1>maxsize20) || (cra[rws1][1] !=
999))
{
if (cra[rws1][1] < maxsize20)
{
printf("\n%1d", cra[rws1][1]);
printf("\nToo Many Circuits for R Entry - Reenter ");
}
else
if ((rws1 < 1) || (rws1>= maxsize20))
{
printf("\nR Out of Range - Reenter ");
printf("R");
scanf("%u,%c",&rws1,&s1);
}
}
if (rws1 == 0)
break;
cr[i][j] =rws1; //R to circuit array
if (rws1>rmax)
rmax = rws1;
if (cra[rws1][0]>maxsize20)
cra[rws1][0] = i; //First circuit for this resistance
else
if (cra[rws1][1]>maxsize20)
cra[rws1][1] = i; //Second circuit for this resistance if ((s1 != 10) && (s1 != 13))
continue;
else
break;
} // {j}
} // {i}
I've tried using following the scanf instruction with a getchar() but that doesn't work either. Keying in a whitespace other than a newline (tab or space) doesn't advance the loop to print out an "R" followed by a scanf. "C" manuals have led me to believe that this would work, but it doesn't.
 
 

Re:Questions about use of scanf / getchar() instructions in Borland C++

This the newsgroup deals with the C++BuilderX IDE, but your question
is about a programming problem.
Please direct your browser at info.borland.com/newsgroups/ and
read the newsgroup descriptions and guidelines. This will help you
find the appropriate newsgroup for your question.
Also the code you post is *much* too complicated for anybody (dare I
say: "including you" to understand). Please shorten it to the minimal
size that still demonstrates your problem; I can't imagine this to be
more than a dozen lines, including #includes.