All pastes #481942 Raw Edit

hebberdcode

public c v1 · immutable
·published 2007-05-11 02:15 UTC
rendered paste body
linux4:assone$ vim countWords.c#include <stdio.h>#include <ctype.h>#include <string.h>#include <stdlib.h>#define TRUE 1#define FALSE 0#define MAX_WORD_LENGTH 100char wordBuffer[MAX_WORD_LENGTH];char* readWord(FILE* fp, int retainCase){        char c = 0;        char *ptr = wordBuffer;        while ((c = fgetc(fp))!= EOF){                if( isalpha(c) || c == '_' ){                        if (!retainCase){                                c = tolower(c);                        }                                *ptr++ = c;                }                else {                        if (ptr > wordBuffer){                                break;                        }                }        }        if (ptr == wordBuffer){                return NULL;        }        *ptr = '\0';        return wordBuffer;}int main(int argc, char *argv[]){        int retainCase = FALSE;        char *output=NULL;        char * fileName=NULL;        FILE* file = stdin;&       if (argc > 3){                fprintf(stderr, "Usage: %s [-c]\n", argv[0]);                return EXIT_FAILURE;        }        for(i=1;i<argc;i++){                if (argv[i] == "-c"){                        retainCase = TRUE;                }                if (file != stdin){                        fprintf(stderr, "Unknown argument '%s'\n", argv[1]);                        return EXIT_FAILURE;                }        }        while ((output=readWord(stdin, retainCase)) != NULL){                printf("%s\n", output);        }        return EXIT_SUCCES;}                                                              57,2-9        All