By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,423 Members | 1,684 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,423 IT Pros & Developers. It's quick & easy.

Input function that terminates by a space and not return.

P: n/a
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[i][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.

Nov 21 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
In article <11**********************@g43g2000cwa.googlegroups .com>,
shan <sr**********@gmail.com> wrote:
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
Nov 21 '05 #2

P: n/a
In article <11**********************@g43g2000cwa.googlegroups .com>,
shan <sr**********@gmail.com> wrote:
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.

Nov 21 '05 #3

P: n/a
shan wrote:
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[i][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.
--
Flash Gordon
Living in interesting times.
Although my email address says spam, it is real and I read it.
Nov 21 '05 #4

P: n/a
"shan" <sr**********@gmail.com> writes:
Can any one tell me an Input function that terminate by pressing
spacebar and not return key.


See the C FAQ, question 19.1.

<http://www.eskimo.com/~scs/C-faq/top.html>

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 21 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.