Open yakra opened 3 years ago
Won't work.
If delimiter (space in this example) is not found, d
is set to 0. And then we try to dereference it.
Having to check whether d
is valid (and then potentially do whatever) outweighs the benefit of losing the bounds checking.
Wait, how about something like this?
// label
char* c = strchr(line, ' ');
if (c) do *c = 0; while (*++c == ' ');
else /* not important in this example */ ;
label = line;
strcspn
takes up time, however little, looping thru an array and checking whether within bounds. Why not skip the looping when we won't need an array?->
strcspn
is used.