1.打开文件
1 FILE *fp; //文件指针 2 fp = fopen("D:\test.txt", "r"); //只读方式打开文件 3 if (fp == NULL) 4 { 5 printf("文件打开失败"); 6 exit(0)
2.读取文本
1 char buf[1000] = { 0 }; //buffer预清空,否则结尾有出乱码的可能 2 fread(buf, sizeof(buf), 1, fp); 3 printf("%s ", buf);
3.结构体定义
1 typedef struct BinaryTree { 2 char str; //单词 3 int count; //出现次数 4 struct BinaryTree * lchild; 5 struct BinaryTree * rchild; 6 }BTNode;
4.给BTNode分配内存
1 BTNode* talloc(void) 2 { 3 return (BTNode*)malloc(sizeof(BTNode)); 4 }
5.比较两个字符串(单词)大小
1 int strcmp(char *s1, char *s2) 2 { 3 int i; 4 for (i = 0; s1[i] == s2[i]; i++) //相等返回0 5 if (s1[i] == '