is it possible to have a cross-platform way to handle backspace and arrows keys within a C or OCaml program?
Actually an OCaml solution would be appreciated but many
The standard way of supporting keyboard input beyond lines of printable characters is through the ncurses library, which has an Ocaml binding. Another common possibility is the readline library (most famously used by Bash).
If all you're doing is reading input line by line, but want your users to have a decent line editor, there's no need to include any support in your program. Instead, just tell your users to use a wrapper program such as rlwrap (which is based on readline) or ledit. These wrappers do provide line edition and history, the two features you list as your requirements. I would recommend that you build input processing into your program only if you want something fancier, such as program-specific completion when the user presses Tab.