[prev] [index] [next]

Profile Example

Consider the following program that
  • searches for words in text containing a given substring
  • displays each such word once (in alphabetical order)

int main(int argc, char*argv[])
{
    char  word[MAXWORD];  /* current word */
    Words matches;        /* list of matching words */
    char  *substring;     /* string to look for */
    FILE  *input;         /* the input file */

    /* ... Check command-line arguments and open input file ... */

    /* Process the file - find the matching words */
    matches = NULL;
    while (getWord(input, word) != NULL) {
        if (contains(word,substring) && !member(word, matches))
            insert(word, &matches);
    }
    printWords(matches);
    return 0;
}