/*将txt版本单词转换为xml格式*/
#include <stdio.h>
#include <io.h>
#include <stdlib.h>
main(int argi,char *args[])
{
FILE *fp,*fp2;
char c='';
char str[80];
int i=0,j=0,k=0,m=0;
clrscr();
if (argi<2)
{
printf("shuru bu hefa\nword word.txt word.xml");
exit(1);
}
if((fp=fopen(args[1],"r"))==NULL)/*源文件,txt格式 单词和解释之间空格,单词之间换行*/
{
printf("can not open file");
exit(0);
}
if((fp2=fopen(args[2],"w"))==NULL)/*目的文件名*/
{
printf("can not open file");
exit(0);
}
fprintf(fp2,"<?xml version=\"1.0\" encoding=\"gb2312\"?><root>");/*声明与根元素*/
c=fgetc(fp);
while (c!=EOF)
{
c=fgetc(fp);
if (c==' '&& k==0)/*单词部分*/
{
fprintf(fp2,"<w><e>%s</e><s>0</s>",str);
for (j=0;j<80 ;j++ )
{
str[j]='\0';
}
i=0;
k=1;/*一行尚未结束*/
continue;
}
if (c==10)
{
fprintf(fp2,"<m>%s</m></w>",str);
for (j=0;j<80 ;j++ )
{
str[j]='\0';
}
i=0;
m++;/*单词计数*/
k=0;/*判断是否一行的变量给与清零*/
continue;
}
str[i++]=c;
}
fprintf(fp2,"%s","</root>");
fclose(fp);
fclose(fp2);
printf("zhuanhuan wancheng !zongji %d ge",m);
}