blob: 5c35e24f78c9151dd07d2e4255bd113ca481d6c5 (
plain) (
tree)
|
|
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include "word.h"
#include "tree.h"
#define MAXWORD 100
#define ARR_SIZE(X) (sizeof(X)/sizeof(X[0]))
int noiseword(char *w);
int main(void)
{
char word[MAXWORD];
struct tnode *root;
int linenum = 0;
root = NULL;
while (getword(word, MAXWORD) != EOF)
if (isalpha(word[0]) && noiseword(word) == -1)
root = addtree(root, word, linenum);
else if(word[0] == '\n')
++linenum;
tprint(root);
tfree(root);
return 0;
}
int noiseword(char *w)
{
const char *noise[] = {
"a",
"an",
"and",
"are",
"in",
"is",
"of",
"or",
"that",
"the",
"this",
"to"
};
int cond, mid;
int low = 0;
int high = ARR_SIZE(noise);
while (low < high) {
mid = (low + high) / 2;
if ((cond = strcmp(w, noise[mid])) < 0)
high = mid;
else if (cond > 0)
low = mid + 1;
else
return mid;
}
return -1;
}
|