int ScanFraction(string str, int index, fraction *fptr) ;When ScanFraction is called it looks for a fraction in the string str starting at position index. If a fraction is found then the value of the fraction is stored in the fraction that the pointer fptr points to. Moreover, ScanFraction returns the position of the character immediately after the fraction it found. For example, after the following function call
new_index = ScanFraction("abc 23/45 xyz", 3, &frac) ;the fraction frac will have the value 23/45 and new_index will have the value 9.
If ScanFraction fails to find a correctly formatted fraction, then it will return a negative number to indicate an error. A return value of -1 indicates that ScanFraction reached the end of the string and did not find a fraction. A return value of -2 indicates that ScanFraction encountered an illegal character for fractions. In both cases, the fraction that fptr points to should remain unchanged. For example, after the function call
new_index = ScanFraction("abc ", 3, &frac) ;new_index will have the value -1; and after the function call
new_index = ScanFraction("abc 23/45 xyz", 0, &frac) ;new_index will have the value -2.
" 24/ 135" "24/135" "24 / 135" " 24 /135"and the following strings are not properly formatted:
" 2 4/ 13 5" "24/ 1 35" "2 4 /135"If you want to, you may implement an extra feature that allows the numerator to be preceded by a negative sign. No other extra features should be implemented.
If your ScanFraction function does not work completely correctly, you should nevertheless include the sample runs which show what went wrong. You will receive more points for showing that you know a problem exists because a bug that you are not aware of is twice as bad as a bug that you know exists.
Richard Chang, email@example.com