Can anyone tell me how to write my own getche() function? I am writing my own so-called "operating system", and I can't use built-in functions like getche() and scanf() etc. Any help would be appreciated.
Thanks
Can anyone tell me how to write my own getche() function? I am writing my own so-called "operating system", and I can't use built-in functions like getche() and scanf() etc. Any help would be appreciated.
Thanks
>I am writing my own so-called "operating system", and I can't use built-in functions like getche() and scanf() etc.
Functions like getche and scanf are typically written using system level APIs. If you're writing an OS, then you need to first implement those APIs and all of the infrastructure required to support them before you can even consider writing getche. I'd say that getche is the least of your problems at the moment.
My best code is written with the delete key.
I know that but I am still just messing around. Please give me some idea of what I can do to write a getche() function.Originally Posted by Prelude
>Please give me some idea of what I can do to write a getche() function.
Perhaps I wasn't clear. Unless you have the framework in place to support such a function, it's physically impossible to implement. It doesn't matter if you're "messing around" or not, you've got roughly a million lines of code to write before getche is a possibility in any non-trivial operating system. Now, if you want to write getche on an existing system like Windows, that's a different story altogether.
My best code is written with the delete key.
1. Write the kernel
2. Write the keyboard driver [and other essentials like serial, usb, mouse, terminal]
3. [Optional but very useful for subsequent development] Write the shell
Now...
4. Write the API [including getchar, getch, getmouse and other functions you deem fit]
Code:#include <stdio.h> void J(char*a){int f,i=0,c='1';for(;a[i]!='0';++i)if(i==81){ puts(a);return;}for(;c<='9';++c){for(f=0;f<9;++f)if(a[i-i%27+i%9 /3*3+f/3*9+f%3]==c||a[i%9+f*9]==c||a[i-i%9+f]==c)goto e;a[i]=c;J(a);a[i] ='0';e:;}}int main(int c,char**v){int t=0;if(c>1){for(;v[1][ t];++t);if(t==81){J(v[1]);return 0;}}puts("sudoku [0-9]{81}");return 1;}