Я предлагаю функцию, подобную этой:
// Argument is a constant pointer to constant character, because
// we neither modify the pointer nor modify the data it points to
void printfletter(const char * const p)
{
if (p == NULL)
{
// The caller passed a null pointer
return; // Don't print anything, just return from the function
}
size_t i; // Used as index into the string
// First skip over all leading spaces, in case there is any
for (i = 0; p[i] != '\0'; ++i)
{
// If the current character is not a space, then break out of the loop
if (!isspace(p[i]))
{
break;
}
}
if (p[i] == '\0')
{
// All of the string was space, no letters or anything else
return; // Don't print anything
}
// State variable, to say if the last character checked was a space
bool last_was_space = true; // Initialize to true, to print the first character
// Iterate over all character in the null-terminated string
// We reuse the index variable i, it will already be positioned at the
// next character to check
for (; p[i] != '\0'; ++i)
{
// If the current character at index i is a space...
if (isspace(p[i]))
{
// ... then set the state variable
last_was_space = true;
}
// Otherwise, if the last character was a space...
else if (last_was_space)
{
// ... then print the current character
putchar(p[i]);
// And reset the state
last_was_space = false;
}
// Else do nothing
}
}
Вышеупомянутая функция должна печатать первый символ каждого «слова», разделенного пробелами.
Со строкой, которую вы показываете ("where are you"
) печатает way
.