I am learning C at university and have to write several codes for it.
I would like to write a function for user input validation (scanf()). It should be a seperate function (not in main()) and have certain Properties. e.g.: User input has to be an integer and between 0 and 100. User input has to be a prime number. User input has to be a specific letter. ... ... I already got something like this, but the problem is, that it is very specific and i have to rewrite it every time for the specific code.
while (scanf("%d", &n) != 1 || n < 1 || n > 100) {
while (getchar() != '\n');
printf("Wrong Input !\n\nn:");
}
I'd like to use the same function for several "programms" with each different requirements. Also i'd like to be able to add new "parameter requirements" to the function. Help really appreciated!