From Steve Summit in the comments. Just use exit(100)
The function you're looking for is exit()
. As argument you pass the return code you want to return. There are standard macros for this, like EXIT_SUCCESS
or EXIT_FAILURE
but you can choose an int
of your choice. When used in function main
, exit(x)
is equivalent to return x
.
You can read about the exit function here: https://port70.net/~nsz/c/c11/n1570.html#7.22.4.4
Another detail is that while(!(scanf("%d %d", rows, cols)))
is wrong. If both row
and cols
are successfully assigned, scanf
will return 2. Sure, what you have written will be treated as success if it returns 2, but it will do the same if it returns 1, which should be treated as a failure. Instead, do while(!(scanf("%d %d", rows, cols)) == 2)
, or even better if it suits your needs, consider a combination of fgets
and sscanf
as described here