Untitled

mail@pastecode.io avatar
unknown
c_cpp
2 years ago
637 B
1
Indexable
Never
#include <stdio.h>
#include <string.h>

int main() {
    printf("Start typing (^Z to end input):\n");

    char str[1000];
    char *token;
    int chara = 0;
    int word = 0;
    int line = 0;

    while (gets(str)) {
        chara += strlen(str);

        token = strtok(str, " ");

        while (token != NULL) {
            token = strtok(NULL, " \n");
            word++;
        }

        line++;
    }

    chara += line; //¥[¦^"\n"ªºcharacters



    printf("Number of chars in input: %d\nNumber of words in input: %d\nNumber of lines in input: %d\n", chara, word, line);

    return 0;
}