Untitled

 avatar
unknown
c_cpp
3 years ago
637 B
4
Indexable
#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;
}
Editor is loading...