0

I need to get an input from user, in this method - all number 0-9 and small letters a-z are allowed, and come one after another, without enter/space and so on. for example:

1d3ab

I need to get an access to each of the elements, (in the example - '1', then d, then '3', and so on). The thing is, I cannot use getch(), but only functions that linux can recognize in stdio ONLY, due to assignment (strict) restrictions. How can I do that?

Thanks very much

Mike
  • 195
  • 2
  • 10
  • can you use [getchar](http://code.wikia.com/wiki/C/getchar)? – pce Nov 16 '13 at 21:06
  • Yes, but it requires Enter, and I have to get all the chars without an enter between them. – Mike Nov 16 '13 at 21:09
  • 5
    I'm not sure this is possible with _just_ `stdio.h`. Standard C doesn't care about how input is buffered, if I recall correctly. ncurses is a library that would work on Linux that can do this if you can change your restrictions. – charmlessCoin Nov 16 '13 at 21:09
  • 1
    See http://stackoverflow.com/questions/7469139/what-is-equivalent-to-getch-getche-in-linux – ArturFH Nov 16 '13 at 21:23
  • Thanks, but I can only use stdio.h, noothing else. – Mike Nov 16 '13 at 21:27
  • why? you could use `read(stdin, buffer, 257)` POSIX Standard ? – pce Nov 16 '13 at 21:29
  • These are the assignment restricions, no can do. – Mike Nov 16 '13 at 21:30
  • 2
    Consider posting whole assignment. Maybe you misunderstood some restrictions? – zubergu Nov 16 '13 at 21:49
  • You should read about non blocking read to do this : http://stackoverflow.com/questions/5616092/non-blocking-call-for-reading-descriptor EDIT : http://www.kegel.com/dkftpbench/nonblocking.html – Yabada Nov 16 '13 at 23:04
  • the instructions are: "Get a base from user, (base can be int in the range 2-36, when a=10, b=11,..., z=35, similarly to hex). Afterwards get a number in this base, without enter between any two digits (example for input - 28/newline/ 3a2 /newline/ 2634 )". I use the /newline/ because I can't use enter in this comment. – Mike Nov 17 '13 at 05:49
  • @Mike I don't think that assignment is possible, if that's a direct quote. There's no way (okay, there are a _few_ circumstances where you could with those restrictions) to determine when one number ends and another begins. Perhaps it means something else, like putting spaces between the numbers? e.g. `28 3a2` – charmlessCoin Nov 17 '13 at 06:38
  • Unfortanately no, this is the way we should get the input, and this is how the checking system works. – Mike Nov 17 '13 at 08:01

0 Answers0