What does str[0]-'0' mean?
If the data type stored in str[0] is the character "1", then subtracting "0" will get the integer 1, instead of the character type "1". If you still don't understand, you can look at the "comparison table of common characters and ASCLL codes" at the end of C programming. The ASCLL value of the character' 0' is 48, while the character' 1' is 49, so str[0]-'0' is equivalent to 49-48= 1.