lsflib/src/tokenchar.c
author Markus Bröker <mbroeker@largo.dyndns.tv>
Thu, 16 Apr 2009 12:49:11 +0200
changeset 40 be3f5582b839
parent 29 7abf6146898e
child 77 49e0babccb23
permissions -rw-r--r--
db_bridge: * libstdc++ for g++-4.3: * cstdlib for getenv and friends... committer: Markus Bröker <mbroeker@largo.homelinux.org>

/**
 * test/demos/lsflib/src/tokenchar.c
 * Copyright (C) 2008 Markus Broeker
 */

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <ctype.h>
#include <string.h>

#define MAXCHARS 80

int tokenchar (FILE * f)
{
    char line[MAXCHARS];

    int i;
    int lines;
    int chars;

    lines = chars = 0;
    *line = 0;

    while ((fgets (line, MAXCHARS, f)) != NULL) {
        for (i = 0; i < strlen (line); i++) {
            switch (line[i]) {
            case '.':
                printf ("%c\n", line[i]);
                lines++;
                break;

            case '?':
                printf ("%c\n", line[i]);
                lines++;
                break;

            case '\n':
                lines++;
                break;

            case '\t':
                break;

            default:
                printf ("UNKNOWN CHAR: %c\n", line[i]);
                chars++;
                break;
            }
        }
        *line = 0;
    }

    rewind (f);
    return chars;
}