l i n u x - u s e r s - g r o u p - o f - d a v i s
Next Meeting:
July 7: Social gathering
Next Installfest:
Latest News:
Jun. 14: June LUGOD meeting cancelled
Page last updated:
2003 Apr 18 15:11

The following is an archive of a post made to our 'vox-tech mailing list' by one of its subscribers.

Report this post as spam:

(Enter your email address)
Re: [vox-tech] a better scanf?? (C-programming question)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [vox-tech] a better scanf?? (C-programming question)

>   Non-blocking with select/poll/busy-looping, reading into a
> buffer, followed by sscanf when a return key is found will certainly
> handle the second case... examples if that's what you want.
>   Otherwise you will have to go with some curses or raw mode input
> to get character by character input from a user, and opens a whole
> can of worms...
>     TTFN,
>       Mike


I am trying to implement this but am unsuccessfull. Could you show me where 
some examples are?? Thank you!!

Here is my code (it may be obviuos that I am a newbie.....I am trying to use 
file descriptors with stdin but the comiler won't let me. All in all....I 
guess I don't know enough about how you could use stdin as a file 
descriptor....any thoughts??

#include <stdio.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/ioctl.h>
#include <unistd.h>
#include <fcntl.h>

char input;
int flag = 0;

int main()
        fd_set rfds;
        struct timeval tv;
        int retval;
        int n;
        int key_press;
        int key_press;
        if((key_press = open(stdin, O_NONBLOCK)) < 0){
                fprintf(stderr, "Error opening stdin\n");
*/    Well this didn't work...it wouldn't let me open stdin...perhaps that is 
a naive thing to try

        while(flag == 0)
                FD_SET(stdin, &rfds);       It didn't like this!!
                tv.tv_sec = 1;
                tv.tv_usec = 0;
                retval = select(FD_SETSIZE, &rfds, NULL, NULL, &tv);
                if (retval > 0) {
                        if (FD_ISSET(stdin, &rfds)) {           ....Or this...
                                n = read(stdin, &input,  1);     .......or 
                                printf("\nInput recorded as %c\n", input);
                                if (input == 'x')
                                        flag = 1;

        return 0;

vox-tech mailing list

LUGOD Group on LinkedIn
Sign up for LUGOD event announcements
Your email address:
LUGOD Group on Facebook
'Like' LUGOD on Facebook:

Hosting provided by:
Sunset Systems
Sunset Systems offers preconfigured Linux systems, remote system administration and custom software development.

LUGOD: Linux Users' Group of Davis
PO Box 2082, Davis, CA 95617
Contact Us

LUGOD is a 501(c)7 non-profit organization
based in Davis, California
and serving the Sacramento area.
"Linux" is a trademark of Linus Torvalds.

Sponsored in part by:
EDGE Tech Corp.
For donating some give-aways for our meetings.