UNBUFFERED INPUT IN C

Started by frktons, June 06, 2010, 08:17:05 PM

Previous topic - Next topic

frktons

Hello C Gurus,

Could anybody help me with this function for unbufferd input
ready for cygwin compiler.

I've tried  to compile in Pelle's C, but something is missing, <termios.h>
and who knows what else.

How can I modify it to be compiled in Pelle's C?

Thanks

Frank
Mind is like a parachute. You know what to do in order to use it :-)

frktons

Just to see how it worked, I installed the Cygwin package and compiled it.
Well, it needs the Cygwin DLL to run, and this is not what I prefer.

So if somebody shows up with the necessary steps to compile it in Pelle's C
I'd be grateful and I'd start modifying the functions to meet my plan:

every single key stroke intercepted and shown on the screen only if they
meet some input criteria [numerical field, Date field, Alfabetic field and so on].

Just copying the missing *.h include files didn't work for me, something
more is needed, something more than I actually am aware or capable of.

Frank
Mind is like a parachute. You know what to do in order to use it :-)

TmX

I don't think Pelles C would able to compile it, since some UNIX stuffs are involved (termios, tty, etc).
Maybe you should try MinGW, which is usually used to port UNIX apps to Windows.

Iif MinGW doesn't provide such things, probably the best thing is to write the equivalent version using Win32 API.

frktons

Quote from: TmX on June 07, 2010, 01:29:39 PM
I don't think Pelles C would able to compile it, since some UNIX stuffs are involved (termios, tty, etc).
Maybe you should try MinGW, which is usually used to port UNIX apps to Windows.

Iif MinGW doesn't provide such things, probably the best thing is to write the equivalent
version using Win32 API.

You are right, and the last resort will be to rewrite it from scratch using win32 APIs,
but who knows, among so many C experts maybe somebody has a faster or better
solution to propose  ::)

Being in the exploration phase I'll accept various solutions just for the sake of learning
different ways of doing the same job.  :P

Mind is like a parachute. You know what to do in order to use it :-)

Ghandi

Quote
You are right, and the last resort will be to rewrite it from scratch using win32 APIs,

You want it to run on Windows? Honestly i would consider rewriting it, not only to make it compatible with Windows, but as a learning exercise. While one cannot deny the benefit of having working code 'on tap' there remains benefits which can only be gained by doing something yourself. Ask questions when you get stuck, but try to do as much of it yourself, that way when you do get it working, it is your achievement and not somebody elses posted example.

I was going to say that you could refer to the C runtime library (the source ships with Visual Studio or you can source it via the web) but its probably going to be more confusion than not having it:


/***
*fgetc.c - get a character from a stream
*
*       Copyright (c) Microsoft Corporation. All rights reserved.
*
*Purpose:
*       defines fgetc() and getc() - read  a character from a stream
*
*******************************************************************************/

#include <cruntime.h>
#include <stdio.h>
#include <dbgint.h>
#include <file2.h>
#include <internal.h>
#include <mtdll.h>

/***
*int fgetc(stream), getc(stream) - read a character from a stream
*
*Purpose:
*       reads a character from the given stream
*
*Entry:
*       FILE *stream - stream to read character from
*
*Exit:
*       returns the character read
*       returns EOF if at end of file or error occurred
*
*Exceptions:
*
*******************************************************************************/

int __cdecl fgetc (
        REG1 FILE *stream
        )
{
        int retval=0;

        _VALIDATE_RETURN( (stream != NULL), EINVAL, EOF);

        _lock_str(stream);
        __try {
        _VALIDATE_STREAM_ANSI_SETRET(stream, EINVAL, retval, EOF);

                if(retval==0)
                {
                        retval = _getc_nolock(stream);
                }

        }
        __finally {
            _unlock_str(stream);
        }

        return(retval);
}

#undef getc

int __cdecl getc (
        FILE *stream
        )
{
        int retval=0;

        _VALIDATE_RETURN( (stream != NULL), EINVAL, EOF);

        _lock_str(stream);
        __try {

        _VALIDATE_STREAM_ANSI_SETRET(stream, EINVAL, retval, EOF);
                if(retval==0)
                {
                        retval = _getc_nolock(stream);
                }

        }
        __finally {
            _unlock_str(stream);
        }

        return(retval);
}

_CRTIMP int (__cdecl _getc_nolock)(
        FILE *stream
        )
{
    return _getc_nolock(stream);
}


jm2c,
Ghandi

frktons

Quote
Honestly i would consider rewriting it, not only to make it compatible
with Windows, but as a learning exercise.

I tend to agree with this point of view. Trying to skip some steps is usually
not going to work.  :lol

Having some working code should be just an occasion to study it and see one of the
many ways to accomplish the task.  :P An inspiration tool  :lol
Mind is like a parachute. You know what to do in order to use it :-)

frktons

All the articles, or books I'm surfing into, give some examples to
focus on possible practical applications of the concepts they talk about.

So why not to use the examples that more skilled and experienced C programmers
can provide?
Mind is like a parachute. You know what to do in order to use it :-)