logo

How to check if a character is a digit

#include <stdio.h> #include <stdlib.h> #include <string.h> int main(int argc, char* argv[]) { char c = 't'; if (c >= 48 && c <= 57) { printf("This is a digit: %c\n", c); } else { printf("This is not a digit: %c\n", c); } if (c >= '0' && c <= '9') { printf("This is a digit: %c\n", c); } else { printf("This is not a digit: %c\n", c); } return 0; }
Course thumb

The C programming language made simple