浅易实现网上动态信息宣布
副标题#e#
1-信息文本,2-目次索引,3-日期索引。
逐日将生成的三组文件上载到相应的子目次即实现了对信息的逐日更新。
方案的利益:
逐日的维护简朴,操纵容易,一般操纵员都能很快上手。
整个操纵安详不变,不会呈现毗连间断网址找不到的环境。
用度很低,不需要购置大型数据库软件和编写专业的查询软件。
实现时间短,可以或许在较短的时间里实现信息的动态网上宣布。
#p#副标题#e#
措施清单:
#include < stdio.h >
#include < string.h >
#include < conio.h >
#define LANXMAX 150
FILE *FileR,*FileW,*FileWIndex;
char Path1[]="c:\\html\\mrcj\\";
char Path2[]="c:\\html\\mrcj\\txt\\";
char Path3[50];
char Path4[]="c:\\html\\ccrindex.htm";
char Path5[]="c:\\html\\html.ini";
char Path6[]="c:\\html\\html-1";
char Path7[]="c:\\html\\html-2";
char Month[10],Date[10];
char FileName[50];
char FileNameIndex[20];
char FilePath1[50]; //...08\\
char FilePath2[50]; //...08\\jxxta\\
char WriteFileName[50];
char IndexFileName[50];
char FileBak[5];
char LanMu;
char Time[20];
char YEAR;
char IndexLANMU[6][19]={"中外财经要闻","法令礼貌政策","经济形势阐明",
"企业改良透视","社会保障制度","改良成长研究"};
int FileNum;
int Yea,Mon,Dat;
void FileIni()
{
switch(Yea)
{
case 98:
case 1998:
YEAR='B';
break;
case 99:
case 1999:
YEAR='J';
break;
default: YEAR='B';
}
if(Yea< 100) Yea+=1900;
FileNum=0;
sprintf(FilePath1,"c:\\fl\\%02d\\",Dat);
sprintf(FileBak,".%1X%02d",Mon,Dat);
}
void AddFileProc(int num)
{
char FLanRead[LANXMAX];
char MainLan[LANXMAX];
char FENLEI[50];
char IndexLan[150];
int i;
sprintf(FENLEI,".中国改良.逐日财经信息.%02d月%02d日\r<br>\r\n<br>\r\n",Mon,Dat);
printf("*");
sprintf(FileName,"%sjxxt%c%03d%s",FilePath2,LanMu,num,FileBak);
if(!(FileR=fopen(FileName,"rb")))
{
printf("cannot open this file\n");
return;
}
//-add htmlhead
fputs("< html > \r\n< body background="../../../../images/bk_creform.jpg\">\r\n",FileW);
//-add htmlhead
fputs(FENLEI,FileW);
fgets(FLanRead,LANXMAX-5,FileR);
//-add index procedure-
sprintf(IndexLan,"< a href=\"txt/%02d/%s\" target=\"new\">%s<br>\r",Dat,FileNameIndex,FLanRead);
//fputs("< br >",FileWIndex);
fputs(IndexLan,FileWIndex);
//-add index procedure-
while(!feof(FileR))
{
fputs("< br >",FileW);
fputs(FLanRead,FileW);
strcpy(FLanRead,"");
fgets(FLanRead,LANXMAX-5,FileR);
}
FLanRead[strlen(FLanRead)-1]='\0';
fputs("< br >",FileW);
fputs(FLanRead,FileW);
fclose(FileR);
fputs("\r\n",FileW);
//-add htmlend
fputs("< /body > \r\n< /html > \r\n",FileW);
//-add htmlend
}
void MakeMainFile()
{
FILE *fp,*fpp,*fppp;
char ccc,fn[50],fff[150];
int n,mm,ddd;
//---html-
if((fppp=fopen(Path4,"wb"))==NULL)
{
printf("不能打开方针文件!\n");
printf("Can not Write the file:%s\n",Path3);
return;
}
if((fpp=fopen(Path6,"rb"))==NULL)
{
printf("不能打开文件数目文件!\n");
printf("Can not Open the file:%s\n",fpp);
return;
}
ccc=fgetc(fpp);
do
{
fputc(ccc, fppp);
ccc=fgetc(fpp);
}while (!feof(fpp));
fclose(fpp);
if((fp=fopen(Path7,"rb"))==NULL)
{
printf("不能打开文件数目文件!\n");
printf("Can not Open the file:%s\n",fp);
return;
}
//-html-
if((fp=fopen(Path5,"rb"))==NULL)
{
printf("不能打开文件数目文件!\n");
printf("Can not Open the file:%s\n",fp);
return;
}
n=0;
fscanf(fp, "%d", &mm);
fscanf(fp, "%d", &ddd);
do
{
n++;
if(mm< 1||ddd< 1||mm >12||ddd >31)
{
printf("日期错误!\n");
printf("date is wrong in: c:\html\html.ini");
return;
}
//-add index procedure-
sprintf(fff,"<tr> <td align=\"center\" bgcolor=\"#FF0000\"><a href=\"../mrcj/INDEX%1X%02d.HTM\" \
target=\"right\" >%d月%d日</a></td></tr>\r",mm,ddd,mm,ddd);
fputs(fff,fppp);
//-add index procedure--
fscanf(fp, "%d", &mm);
fscanf(fp, "%d", &ddd);
}while((!feof(fp))&&(n< 25));
fclose(fp);
//-html-
if((fpp=fopen(Path7,"rb"))==NULL)
{
printf("不能打开文件数目文件!\n");
printf("Can not Open the file:%s\n",fpp);
return;
}
ccc=fgetc(fpp);
do
{
fputc(ccc, fppp);
ccc=fgetc(fpp);
}while(!feof(fpp));
fclose(fpp);
fclose(fppp);
//-html-
}
void AddFile()
{
FILE *fp;
char fn[50],fi[50];
int n;
sprintf(FilePath2,"%sjxxt%c\\",FilePath1,LanMu);
printf("\n%s",FilePath2);
sprintf(fn,"%sjxxt%cdat%s",FilePath2,LanMu,FileBak);
if((fp=fopen(fn,"rb"))==NULL)
{
printf("不能打开文件数目文件!\n");
printf("Can not Open the file:%s\n",fn);
return;
}
if(!fp)
return;
else
FileNum=fgetc(fp);
fclose(fp);
printf(" %02d ",FileNum);
for(n=1;n< =FileNum;n++)
{
sprintf(FileNameIndex,"%c%1X%02d%c%03d.HTM",YEAR,Mon,Dat,LanMu,n);
sprintf(WriteFileName,"%s%02d\\%s",Path2,Dat,FileNameIndex);
if((FileW=fopen(WriteFileName,"wb"))==NULL)
{
printf("不能打开方针文件!\n");
printf("Can not Write the file:%s\n",WriteFileName);
return;
}
AddFileProc(n);
fclose(FileW);
}
}
main()
{
FILE *findex;
int xx;
clrscr();
printf("-\n");
printf("CSRESR MRCJ TXT to HTML for CHINAREFORM.COM \n");
printf(" COPYRIGHT YINLU 1998.4.18 \n");
printf("-\n");
do
{
printf("\nPlease input the date(year month date):");
scanf("%d %d %d",&Yea,&Mon,&Dat);
}
while(!((Mon>0)&&(Mon<13)&&(Dat>0)&&(Dat<32)&&(((Yea>94)&&(Yea<99))||((Yea>1994)&&(Yea<1999)))));
FileIni();
MakeMainFile();
//-add index procedure-
sprintf(IndexFileName,"%sINDEX%1X%02d.htm",Path1,Mon,Dat);
if((FileWIndex=fopen(IndexFileName,"wb"))==NULL)
{
printf("不能打开方针文件!\n");
printf("Can not Write the file:%s\n",IndexFileName);
return 0;
}
fputs("< !DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML//EN\" >\r",FileWIndex);
fputs("< html > \r< head > \r",FileWIndex);
fputs("< meta http-equiv=\"Content-Type\" \r",FileWIndex);
fputs("content=\"text/html; charset=gb_2312-80\" >\r",FileWIndex);
fputs("< meta name=\"GENERATOR\" content=\"Microsoft FrontPage 2.0.yinlu\" >\r",FileWIndex);
fputs("< title >中国改良.逐日财经信息.目次 < /title >\n< /head > \r",FileWIndex);
fputs("< body background=\"../../images/bk_creform.jpg\" >\r",FileWIndex);
fputs("< table border=\"0\" width=\"100%\" bgcolor=\"#FF0000\" > \r",FileWIndex);
fputs("< tr >\r",FileWIndex);
fputs("< td align=\"center\" >< a href=\"#中外财经要闻\"name=\"head\" >
< font color=\"#FFFFFF\" face=\"黑体\" >< strong >中外财经要闻< /strong >< /font >
< /a >< /td > \r",FileWIndex);
fputs("< td align=\"center\" >< a href=\"#法令礼貌政策\" >< fontcolor=\"#FFFFFF\" face=\"黑体\" >
< strong >法令礼貌政策< /strong >< /font >< /a >< /td > \r",FileWIndex);
fputs("< td align=\"center\" >< a href=\"#经济形势阐明\" >< fontcolor=\"#FFFFFF\" face=\"黑体\" >
< strong >经济形势阐明< /strong >< /font >< /a >< /td > \r",FileWIndex);
fputs("< /tr >< tr >\r",FileWIndex);
fputs("< td align=\"center\" >< a href=\"#企业改良透视\" >< fontcolor=\"#FFFFFF\" face=\"黑体\" >
< strong >企业改良透视< /strong >< /font >< /a >< /td > \r",FileWIndex);
fputs("< td align=\"center\" >< a href=\"#社会保障制度\" >< fontcolor=\"#FFFFFF\" face=\"黑体\" >
< strong >社会保障制度< /strong >< /font >< /a >< /td > \r",FileWIndex);
fputs("< td align=\"center\" >< a href=\"#改良成长研究\" >< fontcolor=\"#FFFFFF\" face=\"黑体\" >
< strong >改良成长研究< /strong >< /font >< /a >< /td > \r",FileWIndex);
fputs("< /tr >\n< /table >\n\n",FileWIndex);
//-add index procedure-
for(LanMu='A',xx=0;LanMu< ='F';LanMu++,xx++)
{
//-add index procedure--
switch(xx)
{
case 0:
fputs("< p >< a name=\"中外财经要闻\" >中外财经要闻 < br >\n< /a > \r",FileWIndex);
break;
case 1:
fputs("< p >< a name=\"法令礼貌政策\" >法令礼貌政策 < br >\n< /a > \r",FileWIndex);
break;
case 2:
fputs("< p >< a name=\"经济形势阐明\" >经济形势阐明 < br >\n< /a > \r",FileWIndex);
break;
case 3:
fputs("< p >< a name=\"企业改良透视\" >企业改良透视 < br >\n< /a > \r",FileWIndex);
break;
case 4:
fputs("< p >< a name=\"社会保障制度\" >社会保障制度 < br >\n< /a > \r",FileWIndex);
break;
case 5:
fputs("< p >< a name=\"改良成长研究\" >改良成长研究 < br >\n< /a > \r",FileWIndex);
break;
}
fputs(" \n\0",FileWIndex);
//-add index procedure-
AddFile();
fputs("< /p > \n< p >< a href=\"#head\" >返回页首< br > \n\0",FileWIndex);
}
//-add index procedure-
fclose(FileWIndex);
//-add index procedure-
printf("\nAdd File is Succeed!\nPress Any Key To EXIT! \n");
return 1;
}