Answer the question
In order to leave comments, you need to log in
How to display the first letters of the words in a string?
In the "C" language, the gets() function enters a set of words, and then you need to output the first letters of each of these words to the console. How can this task be completed?
Answer the question
In order to leave comments, you need to log in
Displays the first letters of words.
#include <stdio.h>
#include <ctype.h>
int main(void)
{
int c, wassp;
wassp = 1;
while ((c = getchar()) != EOF) {
if (isspace(c))
wassp = 1;
else if (wassp) {
wassp = 0;
putchar(c);
}
}
putchar('\n');
return 0;
}
[[email protected] c]$ .ansi t.c -o t
[[email protected] c]$ echo "abcd efgh ijkl" | ./t
aei
[[email protected] c]$
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question