Parsing one string in two bases
char *next; unsigned long long n = strtoull("0789a", &next, 10); /* n == 789; *next == 'a' */ With base 0, the leading 0 selects octal instead: parsing stops at '8', after producing 7. The second argument receives the address where parsing ends. section 14.1
strtoull converts the initial numeric portion of a string to an unsigned long long value. Its end-pointer argument lets a caller continue scanning from the first character not consumed. section 14.1
A loop can use strtoull to collect successive numbers:
- Pass the current character pointer as the string argument and pass &next as the end-pointer argument. section 14.1
- Advance to next after each successful conversion; stop when next equals the input pointer, indicating that no number was found. section 14.1
97 static
98 size_t numberline_inner(char const*restrict act,
99 size_t numb[restrict], int base){
100 size_t n = 0;
101 for (char* next = 0; act[0]; act = next) {
102 numb[n] = strtoull(act, &next, base);
103 if (act == next) break;
104 ++n;
105 }
106 return n;
107 }
!@%STYLE%@!
{"css":"{\"css\": \"font-weight: bold;\"}","target":"[[{\"line\":0,\"ch\":1},{\"line\":0,\"ch\":3}],[{\"line\":0,\"ch\":6},{\"line\":0,\"ch\":12}],[{\"line\":1,\"ch\":1},{\"line\":1,\"ch\":3}],[{\"line\":1,\"ch\":6},{\"line\":1,\"ch\":12}],[{\"line\":2,\"ch\":29},{\"line\":2,\"ch\":35}],[{\"line\":3,\"ch\":8},{\"line\":3,\"ch\":14}],[{\"line\":1,\"ch\":30},{\"line\":1,\"ch\":40}],[{\"line\":1,\"ch\":41},{\"line\":1,\"ch\":49}],[{\"line\":2,\"ch\":41},{\"line\":2,\"ch\":49}],[{\"line\":2,\"ch\":1},{\"line\":2,\"ch\":3}],[{\"line\":1,\"ch\":6},{\"line\":1,\"ch\":12}],[{\"line\":2,\"ch\":29},{\"line\":2,\"ch\":35}],[{\"line\":3,\"ch\":8},{\"line\":3,\"ch\":14}],[{\"line\":1,\"ch\":41},{\"line\":1,\"ch\":49}],[{\"line\":2,\"ch\":41},{\"line\":2,\"ch\":49}],[{\"line\":2,\"ch\":52},{\"line\":2,\"ch\":55}],[{\"line\":3,\"ch\":0},{\"line\":3,\"ch\":3}],[{\"line\":1,\"ch\":6},{\"line\":1,\"ch\":12}],[{\"line\":2,\"ch\":29},{\"line\":2,\"ch\":35}],[{\"line\":3,\"ch\":8},{\"line\":3,\"ch\":14}],[{\"line\":4,\"ch\":0},{\"line\":4,\"ch\":3}],[{\"line\":4,\"ch\":8},{\"line\":4,\"ch\":11}],[{\"line\":1,\"ch\":30},{\"line\":1,\"ch\":34}],[{\"line\":4,\"ch\":13},{\"line\":4,\"ch\":17}],[{\"line\":5,\"ch\":0},{\"line\":5,\"ch\":3}],[{\"line\":5,\"ch\":20},{\"line\":5,\"ch\":28}],[{\"line\":6,\"ch\":0},{\"line\":6,\"ch\":3}],[{\"line\":6,\"ch\":10},{\"line\":6,\"ch\":12}],[{\"line\":6,\"ch\":27},{\"line\":6,\"ch\":32}],[{\"line\":7,\"ch\":0},{\"line\":7,\"ch\":3}],[{\"line\":8,\"ch\":0},{\"line\":8,\"ch\":3}],[{\"line\":9,\"ch\":0},{\"line\":9,\"ch\":3}],[{\"line\":9,\"ch\":8},{\"line\":9,\"ch\":14}],[{\"line\":10,\"ch\":0},{\"line\":10,\"ch\":3}]]"}
!@%STYLE%@!
Inspect the complete numberline_inner loop using strtoull, next, and the no-progress test. section 14.1

