.S0 {
color: #808080;
background: #FFFFFF;
}
.S1 {
font-family: 'Comic Sans MS';
color: #007F00;
background: #FFFFFF;
font-size: 9pt;
}
.S4 {
color: #007F7F;
background: #FFFFFF;
}
.S5 {
font-weight: bold;
color: #00007F;
background: #FFFFFF;
}
.S6 {
color: #7F007F;
background: #FFFFFF;
}
.S7 {
color: #7F007F;
background: #FFFFFF;
}
.S9 {
color: #7F7F00;
background: #FFFFFF;
}
.S10 {
font-weight: bold;
color: #000000;
background: #FFFFFF;
}
span {
font-family: 'Verdana';
color: #000000;
background: #FFFFFF;
font-size: 10pt;
}
/*
* 本程序 使用 tc 2.01 编译通过
* 10751331 is QQ group No.
* 把群聊天记录 导出成一个liao.txt 文本文件
* 先登陆群社区然后使用下面网址
* http://group.qq.com/cgi-bin/showGroupMpjPage?PageType=5&CurPage=0&GroupId=10751331
* 得到所有现在群人员名单 保存为name.txt
* 格式为:
* vincent/mg[100011931] 你是我HAppy[76865684] 輕憶/;![76969318]
* Sky↑Archer[77050750] 雨[77434994] 書生小強/aiq[78121686]
* 这两个文件都放在原文件同一个目录
*/
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <conio.h>
#define SS "2005-07-21"
#define TIME "16:52:33"
#define QQ 15
#define NAME 30
#define DAY 13
#define TEMP 30
typedef struct list
{
char qq[QQ];
char name[NAME];
char day[DAY];
char temp[TEMP];
int count;
struct list *next;
}L;
int getline(FILE *fp,char arry[]);
int liu(void); /* 过滤代码 */
int tests(char str[],char text[],int a,int b); /* 测试字符串 */
int inslist(char name[],L *list,char day[],char qq[]);/*插入人名 && 计算 次数*/
void findname(L *head); /*从 name.txt 提取名单 */
int findqq(char name[],char qq[]); /* 从字符串中搜索 qq号码 */
void freelist(L *head); /*销毁链表 */
void paixu(L *head); /* 排序链表 */
L * creatlist(void); /* 创建空链表 */
main()
{
L *head;
FILE *fp, *wp;
int test = 0; /*test*/
char day[DAY];
char name[NAME];
char temp[TEMP];
char qq[QQ];
liu(); /*过滤文件 */
head = creatlist();
findname(head);
fp = fopen("qq.tmp","r");
if (NULL == fp) {
printf("Not Open the qq.tmp file\n");
exit (1);
}
wp = fopen("newqq.txt","w");
if (NULL == wp) {
printf("Not W the newqq.txt file\n");
exit (1);
}
while( fscanf(fp,"%30s",day) != EOF ){
if ( tests(day,SS,0,5) ){
fscanf(fp,"%s",temp);
if ( tests(temp,TIME,2,2) ){
getline(fp,name);
if( findqq(name,qq) ){
inslist(name,head,day,qq);
}
}
}
}
/* printf("head : %d \n",head->count); */
paixu(head);
fprintf(wp,"一共有成员 %d \n"
"-------------------------------------------\n"
"%10s%14s%11s%10s\n\n"
,head->count,"QQ号码"," 姓名 ","最后日期"," 次数 ");
do{
++test;
/* head = head -> next; */
/* printf("qq: %s\n",head->qq); */
head = head -> next;
fprintf(wp,"%10s",head->qq);
fprintf(wp," ");
fprintf(wp,"%14s",head->name);
fprintf(wp," ");
fprintf(wp,"%11s",head->day);
fprintf(wp," ");
fprintf(wp,"%4d\n",head->count);
}
while (NULL != head -> next);
printf("%d\n",test);
fclose(wp);
fclose(fp);
freelist(head);
if (!remove("qq.tmp") )
printf("remove file OK!\n");
else printf("remove file Error !\n");
printf("done !!\n");
getch();
return 0;
}/* main() */
int tests(char str[],char text[],int a,int b)
{
int i = 0;
while ( str[i] != '\0' )
++i;
if ( i < b )
return 0;
while(a <= b){
if(str[a] != text[a])
return 0;
/* printf("str:%c text:%c\n",str[a],text[a]); */
/* getch(); */
++a;
}
return 1;
}
int inslist(char name[],L *list,char day[],char qq[])
{
L *head;
L *newl;
head = list;
/* printf("list next:%d\n",list->next); */
if (list -> next == NULL){
newl = (L *)malloc( sizeof(L) );
if (newl == NULL) {
printf("!!error malloc\n");
exit(1);
}
newl->next = NULL;
newl->count = 0;
strcpy(newl->qq,qq);
strcpy(newl->name,name);
strcpy(newl->day,day);
list -> next = newl;
++head -> count;
printf("new list\n");
return 1;
}
do{
list = list -> next;
/* printf("%s : %s\n",list->qq,qq); */
/* getch(); */
if ( !strcmp(list->qq,qq) ){
++ list -> count;
strcpy(list -> day,day);
strcpy(list -> name,name);
return 0;
}
}
while (list -> next != NULL);
/* printf("add a new NOD \n"); */
if( !strcmp(day,"0000") ) {
newl = (L *)malloc( sizeof(L) );
if (newl == NULL) {
printf("!!error malloc\n");
exit(1);
}
strcpy(newl->qq,qq);
strcpy(newl->name,name);
strcpy(newl->day,day);
newl -> count = 0;
newl -> next = NULL;
list -> next = newl;
++head -> count;
/*printf("inster new save qq :%s\n",qq); */
return 1;
}
return 0;
}/* inslist () */
L * creatlist(void)
{
L *new;
new = (L *)malloc( sizeof(L) );
if (new == NULL) {
printf("!!error malloc\n");
exit(1);
}
new -> qq[0] = '\0';
new -> name[0] = '\0';
new -> day[0] = '\0';
new -> count = 0;
new -> next = NULL;
printf("creatlist OK\n");
return new;
} /* creatlist() */
void freelist(L *head)
{
L *temp;
temp = head -> next;
free(head);
head = temp;
}/* freelist() */
int findqq(char name[],char qq[])
{
int size, i, pot;
size = strlen(name);
/* printf("size : %d is name %s \n",size,name); */
if (name[size-1] != ')')
return 0; /* qq No. error */
/* printf("find ) is : %c\n",name[size]); */
i = 0;
while( name[size-i] != '(') {
++i;
if(size-i < 0)
return 0; /* not find '(' error */
}
pot = size - i;
for (i = 0; pot + i +1<= size-2; i++){
qq[i] = name[pot + i+1];
/* printf("qq[%d]: %c\n",i,qq[i]); */
}
qq[i] = '\0';
name[pot] = '\0';
return 1;
}/* findqq */
void paixu(L *head)
{
L *list,*r, *temp, *hhead;
int max, i, l;
hhead = head;
max = head -> count;
printf("max: %d\n",max);
for (i = 0; i < max; i++){
head = hhead;
for (l = 0; l < max;l++){
list = head -> next;
r = list -> next;
if(list->count > r->count){
/*printf("l: %d\n",l); */
/* printf("rver list:%d r:%d \n",list->count,r->count);
getch(); */
temp = head->next;
head->next = list->next;
list -> next = r->next;
r->next = temp;
}
head = head->next;
}
}
}/* paixu() */
void findname(L *head)
{
FILE *np;
int ch;
int i = 0;
int flag = 0;
int temp ;
char name[NAME];
char qq[QQ];
np = fopen("name.txt","r");
if (NULL == np){
printf("Not Open the name.txt file\n");
exit (1);
}
while( !feof(np) ){
while( isspace ( ch=fgetc(np) ))
;
if ('[' == ch){
temp = fgetc(np);
if ( isdigit(temp) ){
name[i] = '\0';
flag = 1;
ch = temp;
i = 0;
}else ch = temp;
/* a name to save done */
}
if (']' == ch && 1 == flag){
flag = 0;
qq[i] = '\0';
ch = ' ';
i = 0;
inslist(name,head,"0000",qq);
/* a qq number to save done */
}
if (0 == flag){
name[i] = ch;
++i;
}
if (1 == flag){
qq[i] = ch;
/* printf("qq[%d]:%c\n",i,qq[i]); */
++i;
}
}
fclose(np);
printf("name find done !!\n");
getch();
}/* findname() */
/* 过滤代码 */
/* \x14 \x0a || \x0b \x14 \x0a || \x0b \x14 */
int liu(void)
{
FILE *fp, *wp;
int ch;
int flag = 0;
fp = fopen("liao.txt","rb"); /* 聊天记录导出文件 */
if (NULL == fp) {
printf("Not Open the liao.txt file\n");
exit (1);
}
wp = fopen("qq.tmp","wb"); /* 生成新的文件 */
if (NULL == wp) {
printf("Not WP to qq.tmp file\n");
exit (1);
}
while (!feof(fp)){
flag = 0;
ch = fgetc(fp);
if ('\x14' == ch){
/*temp = ch; */
ch = fgetc(fp);
if ('\x0a' == ch)
;
else if ('\x0d' == ch){
ch = fgetc(fp);
if ('\x0a' == ch)
ch = fgetc(fp);
fputc(ch,wp);
}
else fputc(ch,wp);
flag = 1;
}
if ('\x0b' == ch){
ch = fgetc(fp);
if ('\x14' == ch){
ch = fgetc(fp);
if('\x0a' == ch)
;
else fputc(ch,wp);
}else fputc(ch,wp);
flag = 1;
}
if ('\x1a' == ch){
flag = 1;
}
if (0 == flag ){
fputc(ch,wp);
}
}
fclose(fp);
fclose(wp);
printf("liu done !!!!! \n");
getch();
return 0;
}
int getline(FILE *fp,char arry[])
{
char ch;
int i = 0;
int flag = 0;
while ( isspace ( ch=fgetc(fp) ) )
;
do {
arry[i] = ch;
if ( '(' == ch )
flag = 1;
if ( 1 == flag && ')' == ch )
flag = 2;
ch = fgetc(fp);
++i;
if ( i > NAME - 1 )
return 0;
}while ( flag != 2 );
arry[i] = '\0';
/*printf("%s\n",arry); */
return 1;
}
/* 彩色代码由SciTE 生成 */