TC编译通过,但是在winxp下出错!

csfrank 2003-12-12 04:34:44
#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); /*关闭文件:域名列表*/

}

...全文
41 12 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
njuhuangmy 2003-12-15
  • 打赏
  • 举报
回复
使用exit函数,加入<stdlib.h>头!

修改了你的while里面的几个字符串初始化问题

然后,重新执行正确。

注意,你的for里面本来写了0-30 ,这是31个字符!!
我编译的时候,改成0-19了,我在这里贴代码

然后,可执行文件发到你邮箱去。

.net下console app!

#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>

int 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 open maillist.txt error \n"); exit(0);}


if ((p_domainlist=fopen("domainlist.txt","r"))==NULL) {printf("\n open domainlist.txt error!\n"); exit(0);}


if ((p_mailbody=fopen("mailbody.txt","r"))==NULL) {printf("\n open mailbody.txt error !\n"); exit(0);}


i=0; while(!feof(p_mailbody)) Mailbody[i++]=fgetc(p_mailbody);


fclose(p_mailbody);

printf("\n\ninput sender name:");
scanf("%s",Name);

printf("\n\ninput recver name:");
scanf("%s",Subject);

while(!feof(p_maillist))
{
memset(Randstr, 0, sizeof(Randstr));
memset(Sender, 0, sizeof(Sender));
memset(Rcpter, 0, sizeof(Rcpter));
memset(temp, 0, sizeof(temp));
memset(outfile, 0, sizeof(outfile));

memset(line1, 0, sizeof(line1));
memset(line2, 0, sizeof(line2));
memset(line3, 0, sizeof(line3));
memset(line4, 0, sizeof(line4));
memset(line5, 0, sizeof(line5));

for(i=0;i<20;i++) Randstr[i]=97+fmod(rand(),26); /* 31 */

if(feof(p_domainlist)) rewind(p_domainlist);
fscanf(p_domainlist,"%s",temp);

strcpy(Sender,Randstr); strcat(Sender,temp);

fscanf(p_maillist,"%s",Rcpter);

strcpy(line1,">>> "); strcat(line1,Sender);
strcpy(line2,"<<< "); strcat(line2,Rcpter);

strcpy(line3,"From: \""); strcat(line3,Name); strcat(line3,Randstr);
strcat(line3,"\"<"); strcat(line3,Sender); strcat(line3,">");


strcpy(line4,"To: "); strcat(line4,Rcpter);

strcpy(line5,"Subject: "); strcat(line5,Subject); strcat(line5,Randstr);

strcpy(outfile,Randstr); strcat(outfile,".msg");

if ((p_outfile=fopen(outfile,"w"))==NULL) printf("\n error on create output file!\n");

rewind(p_outfile);

fprintf(p_outfile,"%s\n%s\n%s\n%s\n%s\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);

return 0;
}
njuhuangmy 2003-12-13
  • 打赏
  • 举报
回复
sorry:) 还没细看你的问题 就发了上面的回复:)

take it back !

你说不能用8个字符的文件名? 可你程序里 domainlist.txt 前面 就10个字符啦

njuhuangmy 2003-12-13
  • 打赏
  • 举报
回复
首先 解释 你的 为何 文件名字符不能超过 8 个的原因。

看你 用tc2.0 我想 你用的是 98 系统 ?

所以,你进的是 实际上 dos 模式:)

而在 dos模式下, 超过8个字符的文件名 都被 改成 ~1 , ~2 之类的

这是 你不能打开 超过 8个字符(不算扩展名) 的 文件 的原因

你核实 一下
csfrank 2003-12-12
  • 打赏
  • 举报
回复
数组应当没有越界,我放的都很宽裕的
lbaby 2003-12-12
  • 打赏
  • 举报
回复
看看是不是你的数组越界了
小心一下strcat
csfrank 2003-12-12
  • 打赏
  • 举报
回复
但是实际运行以后输出就走样了,这是一个输出实例:(输入是:subject=subject;name=sender)




qlce.msg
<<< juaneylmj@hotmail.com

From: "sendersnlvqlce"<snlvqlce@163.com>
To: juaneylmj@hotmail.com
Subject: subjectsnlvqlce

snlvqlce
测试信体内容测试信体内容测试信体内容测试信体内容测试信体内容测试信体内容测试信体内容测试信体内容测试信体内容测试信体内容测试信体内容测试信体内容测试信体内容测试信<<<< juaneylmj@hotmail.com
.
csfrank 2003-12-12
  • 打赏
  • 举报
回复
我是用TC2.0编译的
编译中没有问题
实际运行的时候遇到几个问题:
1,信体内容过长(超过500个字符)的时候就不能完全输出
2,文件名长度不能超过8

arfi 2003-12-12
  • 打赏
  • 举报
回复
把错误贴出来
csfrank 2003-12-12
  • 打赏
  • 举报
回复
to: njuhuangmy:
编译通过没有问题!但是输出结果就两样了!
下面是输出格式:

>>> ???????@??????? /*发件人地址(Sender):"@"前的部分为随机字符串(randstr),"@"后的部分从域名列表domainlist.txt中循环读取*/
<<< ?????@??????? /*收件人地址(Rcpter):从邮件接收者列表maillist.txt中读取,到文件尾时程序结束*/

From: "????"<????@?????> /*引号内的内容为:发件人名字(Name)+随机字符串(randstr);尖括号内的内容为:发件人地址(Sender)*/
To: ??????@??????? /*收件人地址(Rcpter):从邮件接收者列表maillist.txt中读取,到文件尾时程序结束*/
Subject: ????? /*邮件主题:主题(Subject)+随机字符串(randstr) */

?????????? /*随机串(randstr) */
?????????????????? /*信体内容(Mailbody):信体文件mailbody.txt的内容 */
. /*结束标志:dot+换行符 */


/*这是输出的一系列文件的统一格式:其中的随机字符串(randstr)就是这个文件的文件名*/
csfrank 2003-12-12
  • 打赏
  • 举报
回复
不行啊
njuhuangmy 2003-12-12
  • 打赏
  • 举报
回复
不好意思, xp + .net 环境下 通过!!

你xp下用啥编译的?
arfi 2003-12-12
  • 打赏
  • 举报
回复
加上个#include <stdlib.h>试试

70,020

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧