use strspn / strcspn instead of loops