Welcome, guest! Login / Register - Why register?
Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)

Paste

Pasted as C by Masha ( 13 years ago )
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>

// isupper(c) верно, если c -- буква в верхнем регистре.

//int myisupper(char c)
//{
//    return 'A' <= c && c <= 'Z';





#define IN 1 /* внутри слова */
#define OUT 0 /* вне слова */
/* подсчет строк, слов и символов */

#define CAPS 2
#define MIXED 3
main ()
{
    int c, nl, nw, nc, nb, nm, nk, state, state2;
    state = OUT;
    state2 = OUT;
    nb = nl = nw = nc =nm = nk= 0;

    char fname[80];
    scanf("�s", fname);
    FILE *in = fopen&#40;fname, "rb"&#41;;
    if (NULL == in) {
        fprintf(stderr, "Error: can not open file \"%s\".\n", fname);
        return 1;
    }

    while ((c = fgetc(in)) != EOF) {
        if(isupper(c)) {
            ++nb;
        }
        ++nc;
        if (c == '\n' )
            ++nl;
        if (c == ' ' || c == '\n' || c == '\t')
            state = OUT;
        else if (state == OUT)
        {
            state = IN;
            ++nw;
            if(isupper(c)) {
                ++nm;
            }
        }
        
        if (state2 == OUT) {
            //???
        }
        else if (state2 == CAPS) {
            if (c == ' ' || c == '\n' || c == '\t')
                state2 = OUT;
            ++nk;
        }
        else if (state2 == MIXED) {
            if (c == ' ' || c == '\n' || c == '\t')
                state2 = OUT;
        }
    }
    printf ("%d %d %d %d %d %d\n", nl, nw, nc,nb,nm,nk);
}

 

Revise this Paste

Your Name: Code Language: