Don't modify name at all. Just examine the characters in name one at a time and each time you find an "initial" add it to initials.

A simple way to do this is by scanning the name string using...