1 #ifndef _FILE_H_ 2 #define _FILE_H_ 3 4 #include <string.h> 5 #include <strings.h> 6 #include <stdio.h> 7 #include <stdlib.h> 8 #include <errno.h> 9 #include <stdbool.h> 10 #include "file.h" 11 #include "show.h" 12 13 #define MAX 4096 14 #define MAX_WORD 520 15 16 typedef struct word 17 { 18 char *str; 19 int counter; 20 }word_t; 21 22 extern void write_queue(queue_t *, char *); 23 extern void deal_one_file(queue_t *, char *); 24 extern void deal_one_line(queue_t *, char *); 25 26 void process_word(queue_t *, char*); 27 word_t *mk_word(char *); 28 29 int str_compare(const void*, const void *); 30 #endif//_FILE_H_
1 #ifndef _SHOW_H_ 2 #define _SHOW_H_ 3 4 #include "file.h" 5 #include "queue.h" 6 7 void show_result(queue_t *); 8 void destroy_result(queue_t *); 9 void *output_queue(queue_t *, int); 10 11 void destroy_word(void *); 12 int word_compare(const void *, const void *); 13 14 15 #endif//_SHOW_H_
1 //file.c 2 #include "file.h" 3 #include "queue.h" 4 5 void write_queue(queue_t *s, char *file_list) 6 { 7 char buffer[MAX]; 8 FILE *fp_read_list; 9 10 if(NULL == (fp_read_list = fopen(file_list, "r"))) { 11 printf("Fail fopen%s<file>: %d : %s. ", file_list, __LINE__, strerror(errno)); 12 return ; 13 } 14 15 while(fgets(buffer, MAX, fp_read_list)) 16 { 17 if(' ' == buffer[strlen(buffer) - 1]) { 18 buffer[strlen(buffer) - 1] = '