//countmail.h
#define COUNTM struct countmail
#define STRC 128
COUNTM
{
int count;
char mail[STRC];
COUNTM* next;
};
//
//countmail.cpp
// countmail.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "countmail.h"
#define LEN 128
int main()
{
//
//变量定义
FILE *fp;
COUNTM *head=NULL;
COUNTM *p1=NULL,*p2=NULL,*p3=NULL,*pp=NULL;
char str[LEN];
int i=0;
bool tf=false;
//
//文件打开
if((fp=fopen("26.txt","rb"))==NULL)
{
printf("ERROR!");
exit(0);
}
//
//文件打开成功,开辟空间,建产链表
head=(COUNTM*)malloc(sizeof(COUNTM));
head->next=NULL;
head->count=0;
while(!feof(fp))
{
p2=(COUNTM*)malloc(sizeof(COUNTM));
p2->next=NULL;
p2->count=0;
fgets(str,LEN,fp);
if(*(str+(strlen(str))-1)=='/n')
*(str+(strlen(str)-2))='/0';
if(p1==NULL)
{
i=0;
while(str[i]!='/0')
{
if(str[i]=='@')
break;
i++;
}
strcpy(p2->mail,str+i+1);
p2->count+=1;
p1=p2;
head->count+=1;
head->next=p1;
}
else
{
i=0;
while(str[i]!='/0')
{
if(str[i]=='@')
break;
i++;
}
strcpy(p2->mail,str+i+1);
p2->count+=1;
p2->next=NULL;
p1->next=p2;
p1=p1->next;
head->count+=1;
}
}
//
//统计
p1=head->next;
while(p1)
{
p2=p1->next;
p3=p1;
while(p2)
{
if(strcmp(p1->mail,p2->mail)==0)
{
p1->count+=1;
p3->next=p2->next;
//free(p2);
p2=p2->next;
}
else
{
p3=p3->next;
p2=p2->next;
}
}
p1=p1->next;
}
//
//文件遍历
p1=head->next;
printf("---------------------------------------------");
printf("/ncount E-mail: %d/n",head->count);
printf("---------------------------------------------/n");
while(p1)
{
printf("%s :%d/n",p1->mail,p1->count);
p1=p1->next;
}
///
//
fclose(fp);
return 0;
}