Hi everyone!
We were assigned a project not too long ago that asks us to ask a user to input numbers into a matrix. The user also chooses its dimensions.
My questions is how would I incorporate a validation for the dimensions. Obviously, the only valid dimensions are numerical so I want an error to display if the user types a letter or a special character such as apostrophe or backslash.
My thoughts:
I was thinking that I could have it check the ASCII numerical value and limit those that range from 48 - 57 (numbers 0 - 9) but I cannot seem to get this to work. I would want the number that the ASCII code refers to be used as the dimensions not (48 - 57). Maybe there is an easier way to do this?
Thanks for any and all help!Code:int main(void) { //Declare necessary variables int rowSize = 0; int columnSize = 0; do { //Beginning of column while loopprintf("Please enter the number of columns: "); scanf("%d", &columnSize); //Verify column size if (columnSize > 10)} while (columnSize > 10 || columnSize < 0); ... Same for the row of the matrix.printf("ERROR: The maximum number of columns is 10.\n");else if(columnSize < 0)printf("ERROR: Invalid number of columns. Must be greater than 0.\n");



LinkBack URL
About LinkBacks





I know what a return value is.