统计邮件个数(hotmail)

//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;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值