Writing my own getche() function

This is a discussion on Writing my own getche() function within the C Programming forums, part of the General Programming Boards category; Can anyone tell me how to write my own getche() function? I am writing my own so-called "operating system", and ...

  1. #1
    Registered User
    Join Date
    Sep 2006
    Posts
    98

    Writing my own getche() function

    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

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >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.

  3. #3
    Registered User
    Join Date
    Sep 2006
    Posts
    98
    Quote Originally Posted by Prelude
    >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.
    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.

  4. #4
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >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.

  5. #5
    Registered User
    Join Date
    Mar 2006
    Posts
    725
    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;}

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. using own function in writing a function
    By behzad_shabani in forum C Programming
    Replies: 4
    Last Post: 06-02-2008, 09:22 AM
  3. [help] writing function
    By behzad_shabani in forum C Programming
    Replies: 3
    Last Post: 05-30-2008, 10:32 PM
  4. Change this program so it uses function??
    By stormfront in forum C Programming
    Replies: 8
    Last Post: 11-01-2005, 07:55 AM
  5. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21