blob: f55e857fc3e703432b2352606855c05eb3042bbe (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
|
#include <stdbool.h>
#include <stdint.h>
bool try_sntoi(const char *s, uint32_t n, uint32_t *out) {
uint32_t calc = 0;
for (uint32_t i = 0; i < n; ++i) {
if ((s[i] < '0') || (s[i] > '9'))
return false;
calc = calc * 10 + s[i] - '0';
}
*out = calc;
return true;
}
|