public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* About Keyboards - URGENT!!!!
@ 2000-05-05  4:42 Nelson Guedes Paulo Junior
  2000-05-05  5:11 ` Virgil Palanciuc
  0 siblings, 1 reply; 3+ messages in thread
From: Nelson Guedes Paulo Junior @ 2000-05-05  4:42 UTC (permalink / raw)
  To: Lista GCC

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1079 bytes --]

Hello to anyone.....

I need some help in using the keyboard in C and on the GCC.

I need a function that reads n leters from the keyboard
that folow some rule.
The function prototype will be:

int *read_keyboard(int n;char rule);

The function MUST read exactly n characters and return IMEDIATLY (thingh
that the
functions of the C library doesn't does). If (n==0) the function just
return -1

The rule will be:

'n' or 'N' for numbers
'w' or 'W' for words (only a-z or A-Z)
'a' or 'A' for any character
's' or 'S' for these characters: ({[]})*/\?|><.,;:-_&%$#@!

If rule is not valid, then the function return -2.

Is desired that the param rule be optional so 'A' will be the default
and 
you can use:

int *c;
c = read_keyboard(10);

Or

int *c;
c = read_keyboard(10,'a');

And, is desired too that the function runs on Windows/Dos/Unix/Linux
systems....

Need response urgent.....
Thanks...
-- 
Nelson Guedes Paulo Junior   
E-mail:  <npaulo@linux.ime.usp.br>   UIN: 2489382 (Tender AML)
HomePage: (Em eterna construção)
http://members.xoom.com/DuneKiller/index2.html

^ permalink raw reply	[flat|nested] 3+ messages in thread

* RE: About Keyboards - URGENT!!!!
  2000-05-05  4:42 About Keyboards - URGENT!!!! Nelson Guedes Paulo Junior
@ 2000-05-05  5:11 ` Virgil Palanciuc
  2000-05-06 12:19   ` Mike Corbeil
  0 siblings, 1 reply; 3+ messages in thread
From: Virgil Palanciuc @ 2000-05-05  5:11 UTC (permalink / raw)
  To: Nelson Guedes Paulo Junior, Lista GCC

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1105 bytes --]

   As a first note, I don't think this is the right place for this kind of
questions.

> I need a function that reads n leters from the keyboard
> that folow some rule.
> [....]

  I don't think anybody will write the program for you, so you should have
given a much shorter description for your problem.
  You can use read(...)  to do the job, and specify '0' as the first
parameter (0 means stdin - i.e. the keybord, generally). You should also do
something like
   fcntl(0,F_SETFL,O_RDONLY|O_NONBLOCK);
before any call to your function. (I'm not sure the fcntl call is correct,
you should check the manpages).
> And, is desired too that the function runs on Windows/Dos/Unix/Linux
> systems....
    AFAICT, this will work both on windows/dos and on linux. However,
depending on the compiler you use (under dos), you may need to include
different header files.

> Need response urgent.....
> Thanks...
> --
> Nelson Guedes Paulo Junior
> E-mail:  <npaulo@linux.ime.usp.br>   UIN: 2489382 (Tender AML)
> HomePage: (Em eterna construção)
> http://members.xoom.com/DuneKiller/index2.html

   Virgil.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: About Keyboards - URGENT!!!!
  2000-05-05  5:11 ` Virgil Palanciuc
@ 2000-05-06 12:19   ` Mike Corbeil
  0 siblings, 0 replies; 3+ messages in thread
From: Mike Corbeil @ 2000-05-06 12:19 UTC (permalink / raw)
  To: Lista GCC

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 4197 bytes --]

What about using getc or getchar in a loop which iterates n times?

I'm not going to give more of the algorithm out, but recall doing something
like this for a C course in school and both of these functions are ANSI, which
means that they should be available on all platforms where the C compiler is
ANSI, and (I believe) the same result would occur on all such platforms;
although, supporting all platforms might not be important, especially for a
university or college course.

If getc and or getchar work, then this would eliminate the need for additional
overhead like fcntl, but you'ld need to look up the definition of both of
these, because I think that one may need the user to press Enter or Return,
whilst the function other doesn't; something like getc being irrelevant of
Return or Enter while getchar needs this key to be pressed (you'ld need to
verify).

It's been a long time since I've used these, but these were common for simpler
ways of getting single char user input from stdin.  If the stdin happens to be
from some other location than the default, then I believe that there are
counterpart f functions for either or both of these, for example fgetc.

There's a purpose for read, but it's for lowest level work or tasks; perhaps
also for more assured portability.

getc or getchar may be adequate in this case, and I believe that these use
read while providing a simpler user or programmer interface when special cases
aren't relevant.  For example, an OS probably uses read, while many or most
user programs adequately use getc and or getchar, i.e., it depends on the
purpose; although, ANSI only says what a function must do, instead of how it
must be done, which means that ANSI'd functions can vary wrt things like side
effects.  If that's important, then use read.

Look up the getc, getchar, read, and fcntl functions in this order, to go from
simplest to least (getc and getchar are very similar).  If others are
relevant, then the descriptions you'll read should indicate this.

If you're programming C on Unix or Linux and have Richard Stevens' book on
Programming C for Unix available, then look these functions up in this book.
This book may be adequate for programming in MS OSs, but you'ld need to learn
from trial.

If the question is for a university or college course, then such questions
should be figured out by studying the book.  These functions would be quick to
find by simply browsing through the index, at least if the book is decent.
The way to approach this kind of search is to ask yourself what you want to do
and in this case it's related to character, or string (char is subset of
string, but you can surely skip looking up string in the index, if you have a
decent book), and get or read.  Using this kind of approach, answers can be
quickly found by simply browsing the index (of a decent book) and this can
often be quicker than using mailing lists.

I agree with Virgil that this mailing list is probably not intended for such
questions.

mike corbeil


Virgil Palanciuc wrote:

>    As a first note, I don't think this is the right place for this kind of
> questions.
>
> > I need a function that reads n leters from the keyboard
> > that folow some rule.
> > [....]
>
>   I don't think anybody will write the program for you, so you should have
> given a much shorter description for your problem.
>   You can use read(...)  to do the job, and specify '0' as the first
> parameter (0 means stdin - i.e. the keybord, generally). You should also do
> something like
>    fcntl(0,F_SETFL,O_RDONLY|O_NONBLOCK);
> before any call to your function. (I'm not sure the fcntl call is correct,
> you should check the manpages).
> > And, is desired too that the function runs on Windows/Dos/Unix/Linux
> > systems....
>     AFAICT, this will work both on windows/dos and on linux. However,
> depending on the compiler you use (under dos), you may need to include
> different header files.
>
> > Need response urgent.....
> > Thanks...
> > --
> > Nelson Guedes Paulo Junior
> > E-mail:  <npaulo@linux.ime.usp.br>   UIN: 2489382 (Tender AML)
> > HomePage: (Em eterna construção)
> > http://members.xoom.com/DuneKiller/index2.html
>
>    Virgil.



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2000-05-06 12:19 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-05-05  4:42 About Keyboards - URGENT!!!! Nelson Guedes Paulo Junior
2000-05-05  5:11 ` Virgil Palanciuc
2000-05-06 12:19   ` Mike Corbeil

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).