Skip to content
Check whether a given C-string contains an integer or a floating-point number.
C CMake CSS HTML Python Meson Other
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.circleci
.github
include
tests
.appveyor.yml
.clang-format
.gitignore
LICENSE
README.md
run-tests.bat
run-tests.sh

README.md

Codacy Badge AppVeyor CircleCI SHO Shield License Shield

Checknum

Check whether a given C-string contains an integer or a floating-point number.

This is really more of a snippet than anything else. Feel free to (ab)use this as much as you want.

Usage:

#include "checknum.h"

int main(void) {

  int r = checknum(some_NUL_terminated_c_string, strlen(some_NUL_terminated_c_string));

  switch (r) {
    case 0:
    default:
      // Not a valid number...
      break;
    case 1:
      // The string contains an integer.
      break;
    case 2:
      // The string contains a floating-point number.
      break;
  }
}
You can’t perform that action at this time.