This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Is it posibil to make somthing like kbhit()?

Hi.
I'm using an eval board with C1610 (Phytec KC161).
I know that KEIL doesn't have the function kbhit(). But I need somthing like that function, is it posible to make one? If does anyone know, please give me ideeas, or, the body of he function, even it is for over device.
Thank you.

Parents
  • I think the instruction scanf("%s", command) can read the command I want.

    How large is the command buffer?

    Try to send a couple of extra characters to the unit, and check what happens with your other RAM variables stored directly after the command buffer...

    gets() and scanf() are two of the most dangerous functions available in the C library, and you specifically want to use them despite being warned?

    Immediately plan for using the watchdog in the processor. You might need it sooner than you think. However, the watchdog can only help to restart a hung application. It will not protect the application from producing erroneous results, caused by buffer overruns.

    If you really have decided to use scanf(), at least always specify a maximum field width when retrieving strings. Without a field width, scanf() will behave similar to gets() - trying to receive any number of characters, whatever the size of your buffer is!

Reply
  • I think the instruction scanf("%s", command) can read the command I want.

    How large is the command buffer?

    Try to send a couple of extra characters to the unit, and check what happens with your other RAM variables stored directly after the command buffer...

    gets() and scanf() are two of the most dangerous functions available in the C library, and you specifically want to use them despite being warned?

    Immediately plan for using the watchdog in the processor. You might need it sooner than you think. However, the watchdog can only help to restart a hung application. It will not protect the application from producing erroneous results, caused by buffer overruns.

    If you really have decided to use scanf(), at least always specify a maximum field width when retrieving strings. Without a field width, scanf() will behave similar to gets() - trying to receive any number of characters, whatever the size of your buffer is!

Children
No data