isdigit() Test for Digit
#include <ctype.h>;
int isdigit(c)
int c; Integer value to be tested
isdigit() tests if 'c' is a digit, in the set 0 - 9.
Returns: True (nonzero) if the integer satisfies the test
condition or false (zero) if it does not. The result is
undefined if 'c' is other than an ASCII character or EOF.
Notes: isdigit() is a macro.
-------------------------------- Example ---------------------------------
The following statements open a file, read all the characters in, and
total only those characters that are digits.
#include <ctype.h>
#include <stdio.h> /* for fopen */
FILE *stream;
int ch;
main()
{
int totl = 0;
if ((stream = fopen("input.dat","r+")) != NULL) {
while (!feof(stream))
if (isdigit(ch = getc(stream)))
totl += ch;
}
}
Seealso:
This page last updated on Fri Nov 30 10:48:32 MSK 2001
Copyright © 1992-2001, Vitaly Filatov, Moscow, Russia
Webmaster