Why is wc -c printing spaces before the number?
This is by design. You can see how wc pads “tabs” by removing the -c so it drops the first number in alignment with where the others would be.

You can gobble up the white space if you need with another pipe, but you should plan on this if you’re scripting things on macOS and don’t drop a different wc command down. The options are endless

echo "test" | wc -c | xargs
echo "test" | wc -c | tr -d ' '
echo "test" | wc -c | sed 's/ //g'
echo $(echo "test" | wc -c)