I
I
Ivan Yakushenko2016-04-05 12:12:21
C++ / C#
Ivan Yakushenko, 2016-04-05 12:12:21

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

3 answer(s)
A
abcd0x00, 2016-04-05
@kshnkvn

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;
}

Conclusion
[[email protected] c]$ .ansi t.c -o t
[[email protected] c]$ echo "abcd efgh ijkl" | ./t
aei
[[email protected] c]$

O
Oleg Drozdov, 2016-04-05
@Ardarick

It begs the option to display each character after a space.

K
kstyle, 2016-04-05
@kstyle

see 7. Parsing a string into tokens. in the article

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question