lsflib/src/tokenchar.c
changeset 6 c3dc3eb3b541
child 9 c3fecc82ade6
equal deleted inserted replaced
5:d752cbe8208e 6:c3dc3eb3b541
       
     1 /*
       
     2  *  $Id: tokenchar.c 94 2008-04-05 01:27:30Z mbroeker $
       
     3  * $URL: http://localhost/svn/c/lsflib/trunk/src/tokenchar.c $
       
     4  *
       
     5  */
       
     6 
       
     7 #include <stdio.h>
       
     8 #include <stdlib.h>
       
     9 #include <unistd.h>
       
    10 #include <sys/types.h>
       
    11 #include <sys/stat.h>
       
    12 #include <fcntl.h>
       
    13 #include <ctype.h>
       
    14 #include <string.h>
       
    15 
       
    16 #define MAXCHARS 80
       
    17 
       
    18 int tokenchar (FILE * f)
       
    19 {
       
    20     char line[MAXCHARS];
       
    21     int i;
       
    22     int lines;
       
    23     int chars;
       
    24 
       
    25     lines = chars = 0;
       
    26     *line = 0;
       
    27 
       
    28     while ((fgets (line, MAXCHARS, f)) != NULL) {
       
    29         for (i = 0; i < strlen (line); i++) {
       
    30             switch (line[i]) {
       
    31             case '.':
       
    32                 printf ("%c\n", line[i]);
       
    33                 lines++;
       
    34                 break;
       
    35 
       
    36             case '?':
       
    37                 printf ("%c\n", line[i]);
       
    38                 lines++;
       
    39                 break;
       
    40 
       
    41             case '\n':
       
    42                 lines++;
       
    43                 break;
       
    44 
       
    45             case '\t':
       
    46                 break;
       
    47 
       
    48             default:
       
    49                 printf ("UNKNOWN CHAR: %c\n", line[i]);
       
    50                 chars++;
       
    51                 break;
       
    52             }
       
    53         }
       
    54         *line = 0;
       
    55     }
       
    56 
       
    57     rewind (f);
       
    58     return chars;
       
    59 }