TC编译通过,但是在winxp下出错!
#include <stdio.h>
#include <math.h>
#include <string.h>
main()
{
FILE *p_maillist; /*邮件接收者列表文件指针*/
FILE *p_domainlist; /*域名列表文件指针*/
FILE *p_mailbody; /*信体文件指针*/
FILE *p_outfile; /*输出文件指针*/
char Name[65]; /* 发件人名字*/
char Subject[135]; /* 主题*/
char Randstr[31]; /*随机字符串*/
char Sender[100],Rcpter[100]; /*发件人地址,收件人地址;临时变量*/
char outfile[40]; /*输出文件名;临时变量*/
char Mailbody[65500]; /* 信体内容 */
char line1[150],line2[150],line3[150],line4[150],line5[150]; /*信头的五行内容*/
unsigned int i=0; /*循环变量*/
char temp[100]; /*临时缓冲字符串*/
if ((p_maillist=fopen("maillist.txt","r"))==NULL) {printf("\n打开maillist.txt文件时出错!\n"); exit(0);}
/*打开文件:邮件接收者列表*/
if ((p_domainlist=fopen("domainlist.txt","r"))==NULL) {printf("\n打开domainlist.txt文件时出错!\n"); exit(0);}
/*打开文件:域名列表*/
if ((p_mailbody=fopen("mailbody.txt","r"))==NULL) {printf("\n打开mailbody.txt文件时出错!\n"); exit(0);}
/*打开文件:信体内容*/
i=0; while(!feof(p_mailbody)) Mailbody[i++]=fgetc(p_mailbody);
/*将mailbody.txt的内容写入字符串“Mailbody”当中*/
fclose(p_mailbody); /*关闭文件:信体内容*/
printf("\n\n请输入发件人名字(小于15个汉字,不能有空格):");
scanf("%s",Name);
printf("\n\n请输入邮件主题(小于50个汉字,不能有空格):");
scanf("%s",Subject);
while(!feof(p_maillist)) /*当邮件接收者列表maillist.txt没有到结尾时就执行循环*/
{
strcpy(Randstr,""); /*随机字符串初始化*/
strcpy(Sender,""); /*发件人地址初始化*/
strcpy(Rcpter,""); /*收件人地址初始化*/
strcpy(temp,""); /*缓冲字符串初始化*/
strcpy(outfile,""); /*输出文件名初始化*/
strcpy(line1,"");
strcpy(line2,"");
strcpy(line3,"");
strcpy(line4,"");
strcpy(line5,"");
/*信头的五行内容初始化*/
for(i=0;i<=30;i++) Randstr[i]=97+fmod(rand(),26); /*产生一个30位纯字母随机字符串*/
if(feof(p_domainlist)) rewind(p_domainlist); /*若指针在域名列表domainlist.txt的结尾,则将其重新定位到头部*/
fscanf(p_domainlist,"%s",temp); /*将一个domain赋值给temp缓冲串 */
strcpy(Sender,Randstr); strcat(Sender,temp); /*完成发件人地址(Sender)的组装*/
fscanf(p_maillist,"%s",Rcpter); /*读取一个收件人地址 */
strcpy(line1,">>> "); strcat(line1,Sender); /*完成line1的组装*/
strcpy(line2,"<<< "); strcat(line2,Rcpter); /*完成line2的组装*/
strcpy(line3,"From: \""); strcat(line3,Name); strcat(line3,Randstr);
strcat(line3,"\"<"); strcat(line3,Sender); strcat(line3,">");
/*完成line3的组装*/
strcpy(line4,"To: "); strcat(line4,Rcpter); /*完成line4的组装*/
strcpy(line5,"Subject: "); strcat(line5,Subject); strcat(line5,Randstr); /*完成line7的组装*/
strcpy(outfile,Randstr); strcat(outfile,".msg"); /*完成输出文件名的组装*/
if ((p_outfile=fopen(outfile,"w"))==NULL) printf("\n建立输出文件时出错!\n"); /*打开输出文件*/
rewind(p_outfile); /*将输出文件指针定位在头部*/
fprintf(p_outfile,"%s\n%s\n\n%s\n%s\n%s\n\n",line1,line2,line3,line4,line5); /*输出信头*/
fprintf(p_outfile,"%s\n%s\n",Randstr,Mailbody); /*输出信体*/
fprintf(p_outfile,".\n"); /*输出结束标志*/
printf("\nfile \"%s\" created!\n",outfile); /*输出说明*/
fclose(p_outfile); /*关闭输出文件*/
}
fclose(p_maillist); /*关闭文件:邮件接收者列表*/
fclose(p_domainlist); /*关闭文件:域名列表*/
}