diff options
| author | Ray <[email protected]> | 2019-02-06 14:20:14 +0100 |
|---|---|---|
| committer | Ray <[email protected]> | 2019-02-06 14:20:14 +0100 |
| commit | 7615512af15e67c11c300094adf08198162686d5 (patch) | |
| tree | edaea1054f5d1bf6610e52875e402c0023e46c18 /src/text.c | |
| parent | d0d81ea545c3a46820f35f4caf567b5b047bdd07 (diff) | |
| download | raylib-7615512af15e67c11c300094adf08198162686d5.tar.gz raylib-7615512af15e67c11c300094adf08198162686d5.zip | |
ADDED: TextToInteger()
Custom implementation that returns -1 if it fails (no negative values supported)
Diffstat (limited to 'src/text.c')
| -rw-r--r-- | src/text.c | 20 |
1 files changed, 20 insertions, 0 deletions
@@ -1321,6 +1321,26 @@ const char *TextToPascal(const char *text) return buffer; } + +// Get integer value from text +// NOTE: Negative values not supported +int TextToInteger(const char *text) +{ + int result = 0; + int len = strlen(text); + int units = 1; + + for (int i = len - 1; i >= 0; i--) + { + if ((text[i] > 47) && (text[i] < 58)) result += ((int)text[i] - 48)*units; + else { result = -1; break; } + + units *= 10; + } + + return result; +} + //---------------------------------------------------------------------------------- //---------------------------------------------------------------------------------- |
