Input String.c 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // Custom string input example
  2. #define USE_TI89 // Compile for TI-89
  3. #define USE_TI92PLUS // Compile for TI-92 Plus
  4. #define USE_V200 // Compile for V200
  5. #define MIN_AMS 100 // Compile for AMS 1.00 or higher
  6. #define SAVE_SCREEN // Save/Restore LCD Contents
  7. #include <tigcclib.h> // Include All Header Files
  8. // Custom String Input Function
  9. void InputStr(char *buffer, unsigned short maxlen)
  10. {
  11. SCR_STATE ss;
  12. short key;
  13. unsigned short i = 0;
  14. buffer[0] = 0;
  15. SaveScrState (&ss);
  16. do
  17. {
  18. MoveTo (ss.CurX, ss.CurY);
  19. printf ("%s_ ", buffer);
  20. // Note that two spaces are required only if the F_4x6 font is used
  21. key = ngetchx ();
  22. if (key >= ' ' && key <= '~' && i < maxlen)
  23. buffer[i++] = key;
  24. else if (key == KEY_BACKSPACE && i)
  25. i--;
  26. buffer[i] = 0;
  27. } while (key != KEY_ENTER);
  28. }
  29. // Main Function
  30. void _main(void)
  31. {
  32. char s[20];
  33. clrscr ();
  34. InputStr (s, 20);
  35. printf ("\n%s", s);
  36. ngetchx ();
  37. }