Hi there
1)Is there any method to lock specific keys on the keyboard while getting input
2) How is the memory allocation done in union when it contains one integer variable, one float variable and three character variables
thanx
raajesh
Printable View
Hi there
1)Is there any method to lock specific keys on the keyboard while getting input
2) How is the memory allocation done in union when it contains one integer variable, one float variable and three character variables
thanx
raajesh
1) Explain further. Lock how? No. No portable way. Possible a OS / compiler specific, but you'd need to expalin further what you're trying to do.Quote:
Originally posted by rajesh23
Hi there
1)Is there any method to lock specific keys on the keyboard while getting input
2) How is the memory allocation done in union when it contains one integer variable, one float variable and three character variables
2 ) Sounds like homework. Read up on unions, it's usually the first thing explained on how they work in any book. The size of the union is the size of the largest element.
Quzah.
Hello
How the memory is shared by the variables in it. bcoz there are three char occupying 3 bytes and one integer occupying two bytes have to share the four bytes of float variable. Hope you get it right
can u explain now, also is the allocation machine/OS dependent?
Regarding locking selected keys in the keyboard, we want to do that for validating the input when obtained through scanf. Say u want to lock all the keys except 0 to 9 when u want to enter an integer
thanx
RAAJESH
It is i would say OS specific.But if you intend doing it in DOS then you could use interrupts and scan codes for the keys to do this.
Have a look here. http://vwop.port5.com/advanced/directkey.html
Of course it's shared. That's what a union is. The question you originall posted was how it was allocated. I answered that: It uses the size of the largest element.Quote:
How the memory is shared by the variables in it. bcoz there are three char occupying 3 bytes and one integer occupying two bytes have to share the four bytes of float variable. Hope you get it right
You next problem is that you assume that an integer is 2 bytes. This is only true on old, outdated compilers. Get a new compiler. No one uses 16 bit compilers any more.
Quzah.
Hi,
>>Is there any method to lock specific keys on the keyboard while getting input
Why cant use Isdigit()?.Use can also go for Scancode also.
I've never hurd of unions before do you malloc memory as *void and just asign differnt types of values into it? And could someone please post a link desribing how to do this in linux since it was OS dependent.
Unions
Unions are class types that can contain only one data element at a time (although the data element can be an array or a class type). The members of a union represent the kinds of data the union can contain. An object of union type requires enough storage to hold the largest member in its member-list. Consider the following example:
This was copied from the MSDN Library.Code:#include <stdlib.h>
#include <string.h>
#include <limits.h>
union NumericType // Declare a union that can hold the following:
{
int iValue; // int value
long lValue; // long value
double dValue; // double value
};
int main( int argc, char *argv[] )
{
NumericType *Values = new NumericType[argc - 1];
for( int i = 1; i < argc; ++i )
if( strchr( argv[i], '.' ) != 0 )
// Floating type. Use dValue member for assignment.
Values[i].dValue = atof( argv[i] );
else
// Not a floating type.
{
// If data is bigger than largest int, store it in
// lValue member.
if( atol( argv[i] ) > INT_MAX )
Values[i].lValue = atol( argv[i] );
else
// Otherwise, store it in iValue member.
Values[i].iValue = atoi( argv[i] );
}
return 0;
}
as for locking keys... it depends on the key, if its a special key then you have to use special ways of doing it, if its an alphanumeric key than use :
and if its a key that you want locked discard it if its not, do what ever you want with it (just remember to echo it back).Code:getch(); //from conio.h
and for a linux version of getch, see the Linux Programming FAQ on the Linux programming board.
-LC
So a union is likea struct?
>So a union is likea struct?
A union is basically a structure that takes up only enough memory for the largest member. Because of that, only one member at a time can exist in the memory allowed.
ah, okey, I see :)