You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

79 lines
4.3 KiB

  1. #ifndef USERINPUT_H
  2. #define USERINPUT_H
  3. /// userinput.h provides functions for retrieving user input.
  4. /// The functions are named get + placeholder used by printf for the given datatype.
  5. /// string -> gets
  6. /// short -> gethd
  7. /// int -> getd
  8. /// long -> getld
  9. /// long long -> getlld
  10. /// unsigned short -> gethu
  11. /// unsigned int -> getu
  12. /// unsigned long -> getlu
  13. /// unsigned long long -> getllu
  14. /// double -> getlf
  15. /// The provided functions handle validating the user input and ask again for input
  16. /// with the given message until it is valid.
  17. /// Using the given message gets asks the user to enter a string repeatedly
  18. /// until its length is between minLength and maxLength (both inclusive).
  19. /// The obtained string is then returned.
  20. /// If you don't want to enforce a minLength or a maxLength you can assign it to NULL.
  21. char *gets(char *message, unsigned long *minLength, unsigned long *maxLength);
  22. /// Using the given message gethd asks the user to enter a short repeatedly
  23. /// until it is in the valid range for a short and between min and max (both inclusive) if provided.
  24. /// The obtained short is then returned.
  25. /// If you don't want to enforce a min or max you can assign it to NULL.
  26. short gethd(char *message, short *min, short *max);
  27. /// Using the given message getd asks the user to enter an int repeatedly
  28. /// until it is in the valid range for an int and between min and max (both inclusive) if provided.
  29. /// The obtained int is then returned.
  30. /// If you don't want to enforce a min or max you can assign it to NULL.
  31. int getd(char *message, int *min, int *max);
  32. /// Using the given message getld asks the user to enter a long repeatedly
  33. /// until it is in the valid range for a long and between min and max (both inclusive) if provided.
  34. /// The obtained long is then returned.
  35. /// If you don't want to enforce a min or max you can assign it to NULL.
  36. long getld(char *message, long *min, long *max);
  37. /// Using the given message getlld asks the user to enter a long long repeatedly
  38. /// until it is in the valid range for a long long and between min and max (both inclusive) if provided.
  39. /// The obtained long is then returned.
  40. /// If you don't want to enforce a min or max you can assign it to NULL.
  41. long long getlld(char *message, long long *min, long long *max);
  42. /// Using the given message gethu asks the user to enter an unsigned short repeatedly
  43. /// until it is in the valid range for an unsigned short and between min and max (both inclusive) if provided.
  44. /// The obtained unsigned short is then returned.
  45. /// If you don't want to enforce a min or max you can assign it to NULL.
  46. unsigned short gethu(char *message, unsigned short *min, unsigned short *max);
  47. /// Using the given message getu asks the user to enter an unsigned int repeatedly
  48. /// until it is in the valid range for an unsigned int and between min and max (both inclusive) if provided.
  49. /// The obtained unsigned int is then returned.
  50. /// If you don't want to enforce a min or max you can assign it to NULL.
  51. unsigned int getu(char *message, unsigned int *min, unsigned int *max);
  52. /// Using the given message getlu asks the user to enter an unsigned long repeatedly
  53. /// until it is in the valid range for an unsigned long and between min and max (both inclusive) if provided.
  54. /// The obtained unsigned long is then returned.
  55. /// If you don't want to enforce a min or max you can assign it to NULL.
  56. unsigned long getlu(char *message, unsigned long *min, unsigned long *max);
  57. /// Using the given message getllu asks the user to enter an unsigned long long repeatedly
  58. /// until it is in the valid range for an unsigned long long and between min and max (both inclusive) if provided.
  59. /// The obtained unsigned long long is then returned.
  60. /// If you don't want to enforce a min or max you can assign it to NULL.
  61. unsigned long long getllu(char *message, unsigned long long *min, unsigned long long *max);
  62. /// Using the given message getlf asks the user to enter a double repeatedly
  63. /// until it is in the valid range for a double, between min and max (both inclusive),
  64. /// greater than the given greaterThan and smaller than the given smallerThan.
  65. /// The obtained double is then returned.
  66. /// If you don't want to enforce a min, max, greaterThan or smallerThan you can assign them to NULL.
  67. double getlf(char *message, double *min, double *max, double *greaterThan, double *smallerThan);
  68. #endif