/*
    第2種情報処理技術者試験    平成6年度・春期・午後 問8
                                BohYoh Shibata PREPARATION
*/

#include <stdio.h>
#include <ctype.h>

main()
{
    int count = 0;
    int ch;
    FILE *fptr;

    fptr = fopen("TEXTFILE", "r");
    while ((ch = fgetc(fptr)) != EOF) {
        if (isalnum(ch)) {
            while ((ch = fgetc(fptr)) == '-'
                    || isalnum(ch)) {
                if ( ch == '-' ) {
                    while ((ch = fgetc(fptr)) == ' ');
                    if (ch == '\n') {
                        while ((ch = fgetc(fptr)) == ' ');
                        if (!isalnum(ch))
                            break;
                    } else if (!isalnum(ch))
                        break ;
                }
            }
            count++;
            if ( ch == EOF )
                break;
        }
    }
    fclose(fptr);
    printf("** word count =   %d  **\n", count);
}