| 896 | {{{#!protected |
| 897 | **kinit.h** |
| 898 | {{{#!c |
| 899 | #include <harch.h> |
| 900 | #include <guess.h> |
| 901 | |
| 902 | char hello[] = "Hello World!\n\n"; |
| 903 | char end[] = "\nend!\n"; |
| 904 | |
| 905 | void kinit (void) |
| 906 | { |
| 907 | tty_write (0, hello, sizeof (hello) ); // print hello string |
| 908 | guess(); |
| 909 | tty_write (0, end, sizeof (end)); // print end string on terminal 0 |
| 910 | while (1); // infinite loop |
| 911 | } |
| 912 | }}} |
| 913 | **guess.h** |
| 914 | {{{#!c |
| 915 | #ifndef _GUESS_H_ |
| 916 | #define _GUESS_H_ |
| 917 | |
| 918 | extern void guess (void); |
| 919 | |
| 920 | #endif |
| 921 | }}} |
| 922 | **guess.c** |
| 923 | {{{#!c |
| 924 | include <guess.h> |
| 925 | #include <harch.h> |
| 926 | #include <hcpu.h> |
| 927 | |
| 928 | #define msg(s) tty_write(0,s,sizeof(s)) |
| 929 | #define get(c) tty_read(0,&c,1) |
| 930 | |
| 931 | void guess (void) |
| 932 | { |
| 933 | char c; |
| 934 | int num; |
| 935 | int random; |
| 936 | |
| 937 | do { |
| 938 | random = clock() % 10; // only one digit |
| 939 | do { |
| 940 | do { |
| 941 | msg("Donnez un nombre : "); |
| 942 | get(c); |
| 943 | } while ( (c < '0') && (c > '9') ); |
| 944 | num = c - '0'; |
| 945 | |
| 946 | if (num < random) |
| 947 | msg(" —> trop petit\n"); |
| 948 | else if (num > random) |
| 949 | msg(" —> trop grand\n"); |
| 950 | |
| 951 | } while (random != num); |
| 952 | |
| 953 | msg("\nGagné\n"); |
| 954 | msg("\nOn recommence [Y]/N ? "); |
| 955 | get(c); |
| 956 | msg("\n\n"); |
| 957 | |
| 958 | } while (c != 'N'); |
| 959 | } |
| 960 | }}} |
| 961 | }}} |