I can speak english a little. And I am sorry if I say(write) anything wrongs.
I want to know how to allocate memory. I know function "malloc()" . I want to know the other way to allocate memory. And I want to know how to put execute file(.exe file) to process in my allocate memory.
A second quesion is I want to know how to get keyboard in dev-c++(not mean "scanf" or "cin"). I have learn Turbo C before. In TC(Turbo C) it have "key=bioskey(0);" ,but in dev-c++ it doesn't have. My problem is I use infinite loop("while(1)"). And I want to get keyboard anytimes I want. See my TC code(algorithm) is easy than I explan.
In this code. The loop will run forever until I push enter in keyboard.
I want to do like this code in dev-c++. Please help me.
Thank you for read my problem.If someone know web site, which have help file about dev-c++(all function in dev-c++).Please give me an URL. Thank you again
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2007-02-12
1) '\r' is the escape sequence for the <carriage-return> character. This is the character that is buffered when you press <ENTER>. The standard library functions typically translate this to '\n' (<newline>), which is typically the ASCII <line-feed> character. _getch() does not do such translation.
2) 100 char sized memory units (in practice this always means bytes except possibly on some very unusual architectures).
3) argc and argv are used to deal with command line arguments (arguments passed to the application via teh command line). If your program does not use arguments, you can omit them. argc is the number of arguments, and argv is a pointer to an array of argument strings.
4) Not sure what you mean. Try asking the question in your native language or re-phrasing your question.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
In your second question.If I get it right, you want to take key input and wants to print its ascii value on screen. You can use the following program. Actually, when you press a key and stores its value in an int variable, its ascii value is stored. If you store its value in an character, the ascii value is converted into its character equivalent. In the program below, please note that the ascii value of "Enter" is 10.
include <iostream>
using namespace std;
int main(void)
{
char keyvalue;
int ascii;
while (ascii!=10)
{
cout<<"\nPlease press a key";
cin>>keyvalue;
ascii=keyvalue;
cout<<"\nYou pressed "
<<keyvalue
<< " and its ascii equivalent is "
<< ascii;
cout<<"\n";
};
}
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Err! In the example I posted above, pressing enter will not exit from the program, you may use (escape key) to exit from program.
while (ascii=!27)
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2007-02-10
The "other way" of allocating memory? How many ways do you need. In C++ you would use the 'new' operator to allocate memory. This differs from malloc in that it also invokes the constructor for each object allocated.
In C memory is either allocated automatically (a local function variable), statically (either a global variable or one explicitly declared static), or dynamically (using malloc, calloc, and relloc).
bioskey() as its name implies works by accessing the BIOS keyboard routine - this is ancient 16bit code is no longer used by Windows - to do so requires an expensive switch from 32bit protected mode to 16bit real mode and back. The PC BIOS was developed 27 years ago and you should have stopped relying on it a long time ago, it is largely obsolete.
The problem with stdio and iostream methods of console input, such as cin, getchar(), or scanf() as you are probably aware is that they are line oriented, so even when only wanting a single key press, the input function will not return until ENTER has been pressed and the whole line is buffered. To overcome this you need some platform specific input method, and as you have discovered bioskey() is indeed platform specific - specific to 16 bit DOS programs.
There are a number of methods in Windows depending on what you want to achieve:
ReadConsoleInput() http://msdn2.microsoft.com/en-us/library/ms684961.aspx reads keyboard, mouse, and window re-size events. This is more flexible than ReadConsole() and is more line bioskey() because for example reports the scan-code for a key (although not necessarily the same scan-codes you are familiar with from bioskey), so works with keys that do not produce a printable character such as 'shift' or 'ctrl', it also reports key-up and key-down as separate events.
Clifford
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
In this code. It will show "hello world" infinite times until press Enter.
I want to do like this in "dev-c++". Run any process infinite times until I press somethings to break its.
thanks again.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2007-02-11
Well that is easy, and even in your MS-DOS/Turbo C version you did it the hard way - you would have better using getch() from conio - still not portable, but more so that bioskey(). The MS library that MinGW uses has a conio library that is not the same as Borland's, but can be used in this case:
This is not necessarily good code, but does directly re-implement your original code. Note that in Windows, this process will display extrordinarily fast (so you cannot read it), and will hog all the CPU cycles for itself while doing it.
Clifford
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
1.What is "\r" mean? I never seen its before.
2.In function "malloc"
(char )malloc(100) ,its mean allocate 100 bit or 100 byte?
And what is it return? Is it return address?
3.main(int argc,char argv[])
What is argc, argv? Why needs?
4.My homework is Job Scheduler. Simulation its by allocate memory and put exe file to execute in my allocate memory. How can I put exe file to execute in my allocate memory?
Please give me some hints.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I can speak english a little. And I am sorry if I say(write) anything wrongs.
I want to know how to allocate memory. I know function "malloc()" . I want to know the other way to allocate memory. And I want to know how to put execute file(.exe file) to process in my allocate memory.
A second quesion is I want to know how to get keyboard in dev-c++(not mean "scanf" or "cin"). I have learn Turbo C before. In TC(Turbo C) it have "key=bioskey(0);" ,but in dev-c++ it doesn't have. My problem is I use infinite loop("while(1)"). And I want to get keyboard anytimes I want. See my TC code(algorithm) is easy than I explan.
define enter 0x1c0d
int main()
{
while(1)
{
if(kbhit())
{
key=bioskey(0);
if(key==enter)
break;
}
}
}
In this code. The loop will run forever until I push enter in keyboard.
I want to do like this code in dev-c++. Please help me.
Thank you for read my problem.If someone know web site, which have help file about dev-c++(all function in dev-c++).Please give me an URL. Thank you again
1) '\r' is the escape sequence for the <carriage-return> character. This is the character that is buffered when you press <ENTER>. The standard library functions typically translate this to '\n' (<newline>), which is typically the ASCII <line-feed> character. _getch() does not do such translation.
2) 100 char sized memory units (in practice this always means bytes except possibly on some very unusual architectures).
3) argc and argv are used to deal with command line arguments (arguments passed to the application via teh command line). If your program does not use arguments, you can omit them. argc is the number of arguments, and argv is a pointer to an array of argument strings.
4) Not sure what you mean. Try asking the question in your native language or re-phrasing your question.
In your second question.If I get it right, you want to take key input and wants to print its ascii value on screen. You can use the following program. Actually, when you press a key and stores its value in an int variable, its ascii value is stored. If you store its value in an character, the ascii value is converted into its character equivalent. In the program below, please note that the ascii value of "Enter" is 10.
include <iostream>
using namespace std;
int main(void)
{
char keyvalue;
int ascii;
while (ascii!=10)
{
cout<<"\nPlease press a key";
cin>>keyvalue;
ascii=keyvalue;
cout<<"\nYou pressed "
<<keyvalue
<< " and its ascii equivalent is "
<< ascii;
cout<<"\n";
};
}
Err! In the example I posted above, pressing enter will not exit from the program, you may use (escape key) to exit from program.
while (ascii=!27)
The "other way" of allocating memory? How many ways do you need. In C++ you would use the 'new' operator to allocate memory. This differs from malloc in that it also invokes the constructor for each object allocated.
In C memory is either allocated automatically (a local function variable), statically (either a global variable or one explicitly declared static), or dynamically (using malloc, calloc, and relloc).
bioskey() as its name implies works by accessing the BIOS keyboard routine - this is ancient 16bit code is no longer used by Windows - to do so requires an expensive switch from 32bit protected mode to 16bit real mode and back. The PC BIOS was developed 27 years ago and you should have stopped relying on it a long time ago, it is largely obsolete.
The problem with stdio and iostream methods of console input, such as cin, getchar(), or scanf() as you are probably aware is that they are line oriented, so even when only wanting a single key press, the input function will not return until ENTER has been pressed and the whole line is buffered. To overcome this you need some platform specific input method, and as you have discovered bioskey() is indeed platform specific - specific to 16 bit DOS programs.
There are a number of methods in Windows depending on what you want to achieve:
ReadConsole() http://msdn2.microsoft.com/en-us/library/ms684958.aspx reads characters from the keyboard in either Unicode or ANSI charactersets.
ReadConsoleInput() http://msdn2.microsoft.com/en-us/library/ms684961.aspx reads keyboard, mouse, and window re-size events. This is more flexible than ReadConsole() and is more line bioskey() because for example reports the scan-code for a key (although not necessarily the same scan-codes you are familiar with from bioskey), so works with keys that do not produce a printable character such as 'shift' or 'ctrl', it also reports key-up and key-down as separate events.
Clifford
Thanks for answer my question.
I knew how to get ascii code.
//Turbo C Code
define enter 0x1c0d
int main()
{
while(1)
{
if(kbhit())
{
key=bioskey(0);
if(key==enter)
break;
}
cout<<"hello world";
}
}
In this code. It will show "hello world" infinite times until press Enter.
I want to do like this in "dev-c++". Run any process infinite times until I press somethings to break its.
thanks again.
Well that is easy, and even in your MS-DOS/Turbo C version you did it the hard way - you would have better using getch() from conio - still not portable, but more so that bioskey(). The MS library that MinGW uses has a conio library that is not the same as Borland's, but can be used in this case:
Then the code would look thus:
include <conio.h>
include <iostream>
using namespace std ;
int main()
{
while(1)
{
if(_kbhit())
{
char key = _getch() ;
if(key=='\r')
break;
}
cout<<"hello world";
}
}
This is not necessarily good code, but does directly re-implement your original code. Note that in Windows, this process will display extrordinarily fast (so you cannot read it), and will hog all the CPU cycles for itself while doing it.
Clifford
Thank you very much Mr. Clifford.
I have some question.
1.What is "\r" mean? I never seen its before.
2.In function "malloc"
(char )malloc(100) ,its mean allocate 100 bit or 100 byte?
And what is it return? Is it return address?
3.main(int argc,char argv[])
What is argc, argv? Why needs?
4.My homework is Job Scheduler. Simulation its by allocate memory and put exe file to execute in my allocate memory. How can I put exe file to execute in my allocate memory?
Please give me some hints.