Initials

tl;dr

Implement a program that, given a person’s name, prints a person’s initials, per the below.

$ ./initials
Regulus Arcturus Black
RAB

Specification

Design and implement a program, initials, that, given a person’s name, prints a person’s initials.

  • Implement your program in a file called initials.c in a directory called initials.

  • Your program should prompt a user for their name using get_string to obtain their name as a string.

  • You may assume that the user’s input will contain only letters (uppercase and/or lowercase) plus single spaces between words. You don’t need to worry about names like Joseph Gordon-Levitt, Conan O’Brien, or David J. Malan!

  • Your program should print the user’s initials (i.e., the first letter of each word in their name) with no spaces or periods, followed by a newline (\n).

Walkthrough

Usage

Your program should behave per the examples below. Assumed that the underlined text is what some user has typed.

$ ./initials
Zamyla Chan
ZC
$ ./initials
robert thomas bowden
RTB

Testing

check50

check50 cs50/2017/x/initials/less

Staff’s Solution

~cs50/pset2/initials

FAQs

Might the user’s input start or end with spaces?

No, you may assume that the only spaces in the user’s input will be single spaces between words. A previous version of this problem’s walkthrough incorrectly stated that there might be spaces at the start or end of the user’s input, but the video has since been fixed! Apologies for any confusion!

Changelog

  • 2016-09-14

    • Corrected walkthrough, added FAQ about spaces at input’s start and end.

  • 2016-09-09

    • Initial release.