function digit = ch_to_digit ( c )

%*****************************************************************************80
%
%% ch_to_digit() returns the integer value of a base 10 digit.
%
%  Example:
%
%     C   DIGIT
%    ---  -----
%    '0'    0
%    '1'    1
%    ...  ...
%    '9'    9
%    ' '   -1
%    'X'   -1
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    10 September 2015
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    character C, the decimal digit, '0' through '9' are legal.
%
%  Output:
%
%    integer DIGIT, the corresponding integer value.  If C was
%    'illegal', then DIGIT is -1.
%
  if ( '0' <= c && c <= '9' )

    digit = c - '0';

  else

    digit = -1;

  end

  return
end
