Input function that terminates by a space and not return.

S

shan

Can any one tell me an Input function that terminate by pressing
spacebar and not return key.
Functions like scanf,getchar,getc when invoked they allow whatever
typed after a space they terminate by pressing enter only.
I am using turboc++.
consider the following program in which 2 matrices are given by user.

for(i=0;i<rows;i++)
{
for(j=0;j<cols;j++)
{
if ('\n'==getchar())
break;
else
scanf("%d",& b[j]);
}
}

the matrix should be inputted in the form 1 2 3
4
5 6
7
8 9
So after each space j should be incremented.After each return i should
be incremented.
 
R

Richard Tobin

Can any one tell me an Input function that terminate by pressing
spacebar and not return key.
Functions like scanf,getchar,getc when invoked they allow whatever
typed after a space they terminate by pressing enter only.

On most operating systems, by default, characters typed are not
available to the user until and end-of-line characters is typed.
Of course, there's a way to overcome this, but it depends on the
operating system and can't be done using just standard C functions.

So you need to ask on a newsgroup for the operating system you use.
I am using turboc++.

That sounds like a C++ compiler, but I imagine the situtation is the
same with C++.

-- Richard
 
K

Kenny McCormack

Can any one tell me an Input function that terminate by pressing
spacebar and not return key.
Functions like scanf,getchar,getc when invoked they allow whatever
typed after a space they terminate by pressing enter only.
I am using turboc++.

Allow me to be the first to say this - and I say it from the deepness of my
heart, with all the kindness and love one has come to associate with the
helpful posts you get in this newsgroup:

Not portable. Can't discuss it here. Blah, blah, blah.
 
F

Flash Gordon

shan said:
Can any one tell me an Input function that terminate by pressing
spacebar and not return key.

Standard C does not have one. You will have to ask in a group dedicated
to your system.
Functions like scanf,getchar,getc when invoked they allow whatever
typed after a space they terminate by pressing enter only.
I am using turboc++.
consider the following program in which 2 matrices are given by user.

for(i=0;i<rows;i++)
{
for(j=0;j<cols;j++)
{
if ('\n'==getchar())
break;
else
scanf("%d",& b[j]);
}
}

the matrix should be inputted in the form 1 2 3
4
5 6
7
8 9
So after each space j should be incremented.After each return i should
be incremented.


Do you really need to receive the input on a space? To me it looks like
you might as well use fgets to read a line at a time then process each
line as you receive it. This way it will be easier to handle errors.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,053
Latest member
BrodieSola

Latest Threads

Top