diff options
Diffstat (limited to 'src/util/util.c')
-rw-r--r-- | src/util/util.c | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/src/util/util.c b/src/util/util.c index d3e8742..05701c6 100644 --- a/src/util/util.c +++ b/src/util/util.c @@ -23,12 +23,12 @@ void *kai_expand_array(void **array, size_t *count, size_t element_size) } -int kai_text_to_reals(ka_real_t *dest, const char *str, size_t count) +size_t kai_text_to_reals(ka_real_t *dest, const char *str, size_t count) { char *nptr = (char*) str; char *end; - int result = count; + size_t result = count; for (int i=0; i<count; i++) { dest[i] = KA_STR_TO_REAL(nptr, &end); @@ -40,3 +40,22 @@ int kai_text_to_reals(ka_real_t *dest, const char *str, size_t count) return result; } + + +size_t kai_text_to_longs(long *dest, const char *str, size_t count) +{ + char *nptr = (char*) str; + char *end; + + size_t result = count; + + for (int i=0; i<count; i++) { + dest[i] = strtol(nptr, &end, 10); + if (nptr == end) { + result -= 1; + } + nptr = end; + } + + return result; +} |