int main() { int buf_len = BUFLEN; //char buf[buf_len], *wordptr; char *wordptr; //buf[0] = '\0'; char * buffer = calloc(BUFLEN, sizeof(char)); /* ... set up word filing module ... */ init_table(); /* ... read words and store them ... */ /* was: scanf("%s", buf) */ while ( (buffer = read_word(buffer, &buf_len)) != NULL ){ if (DEBUG) printf("buf = %s, buf_len: %d\n", buffer, buf_len); convert_to_lower_case( buffer ); if ( in_table( buffer ) == YES ) { if (DEBUG) printf("main: found %s in table with a value of %d ", buffer, lookup( buffer )); update( buffer, 1 + lookup( buffer ) ); } else if ( insert( buffer, 1 ) == NO ){ fprintf(stderr,"wordfreq: out of memory\n"); exit(1); } } /* ... move cursor down the table printing out results */ if (DEBUG) printf("printing the results starting with %s \n", firstword()); for( wordptr = firstword() ; wordptr != NULL; wordptr = nextword() ) printf("%5d\t%s\n", lookup( wordptr ), wordptr ); //char hello[] = "hello"; //word_delete(hello); return 0; }
int countword(char *s) { int i=0; if( *(s=firstword(s)) ) i++; while( *(s=nextword(s)) ) i++; return(i); }
void mailmerge( symtab_t *tp, FILE *fp) { int c; if ( strcmp(firstword(tp),"complete") == 0 ) { printf("\nMailmerge found the complete marker\n"); while( ( c = fgetc(fp)) != EOF ) { putchar(c); } show_table(tp); fseek(fp, 0L, 0); } else { printf("\nMailmerge did not find complete\n"); //error out here } //exit(1); }
int main(void) { char * str; char string[80]; str = string; puts("\n"); puts("Type a line of text . . ."); firstword(str); puts(str); return 0; }
void cElementManager::addElement (const string &name, list<sElementPart *> contents, list<string> attlist, map<string, string> attdefault, bool open, bool empty, int tag, string flag) { //sanity checks if (elementDefined (name)) { results->addToList (results->createError ("Multiple definition of element " + name + "!")); return; } sElement *e = new sElement; e->open = open; e->empty = empty; if ((tag >= 20) && (tag <= 99)) { e->tag = tag; if (lineTags.count (tag)) results->addToList (results->createError ("Element " + name + " uses an already assigned line tag!")); lineTags[tag] = name; } else e->tag = 0; e->flag = flag; //assign element contents, generating the list of closing tags e->element.clear(); list<sElementPart *>::iterator it; for (it = contents.begin(); it != contents.end(); ++it) { sElementPart *ep = *it; if (ep->istag) { string tag = lcase (firstword (ep->text)); if (elementDefined (tag)) { if (open && !(openElement (tag))) { delete ep; results->addToList (results->createError ("Definition of open " + name + " tag contains secure tag " + tag + "!")); } else if (empty && !(emptyElement (tag))) { delete ep; results->addToList (results->createError ("Definition of empty " + name + " tag contains non-empty tag " + tag + "!")); } else { e->element.push_back (ep); if (!emptyElement(tag)) e->closingseq.push_front (tag); } } else { //element doesn't exist yet - we must believe that it's correct e->element.push_back (ep); if (!empty) e->closingseq.push_front (tag); results->addToList (results->createWarning ("Definition of element " + name + " contains undefined element " + tag + "!")); } } else e->element.push_back (ep); } //assign the element definition elements[name] = e; //set attribute list setAttList (name, attlist, attdefault); }