编译后在命令行环境下运行exe程序并 <文件名 以读取文件 >>文件名 输出到文件
/**/
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <stdlib.h>
#define MAX 100
#define BUFFSIZE 100
struct tnode{
char *word;
int count;
struct tnode *left;
struct tnode *right;
};
char buf[BUFFSIZE];
int bufp=0; //buf下标
int getch(void)
{
return (bufp>0) ? *( buf+(--bufp) ) : getchar();
/*如果buf不是空的,就返回栈顶下面的那层,如果是空的,就接受一个键盘输入*/
}
void ungetch (char c)
{
if (bufp>BUFFSIZE)
printf ("ungetch:too many char\n");
else
*(buf+(bufp++))=c; //如果buf没满,就将函数参数存储进buf
}
struct tnode *addtree (struct tnode *, char *);
void treeprint (struct tnode *);
int getword(char *, int);
int main ()
{
struct tnode *root;
char word[MAX];
root=NULL;
while (getword (word, MAX)!=EOF) //这里的结束条件是到达文件末尾标记EOF
if (isalpha(*word))
root=addtree(root, word);
treeprint (root);
r