kida
初级用户
积分 139
发帖 63
注册 2007-10-20
状态 离线
|
『楼 主』:
[转贴]reg文件转换成bat文件
经常用到一些.reg文件,觉得合并时老是要确定有点麻烦,于是写了个可以把.reg文件转换成同样效果的C 程序
转换后如果出现乱码,那是因为编码的问题,只需把需要转换的.reg文件的内容复制到一个新件的文本文件再转换即可
#include "stdio.h"
#include "stdlib.h"
void main()
{
char oriname[40],tarname[40];
char ch,ah;
FILE *fp1,*fp2;
while(1)
{ clrscr();
printf("The filename is not more than 8 characters \n\n");
printf("Original file(*.reg): ");
scanf("%s",oriname);
if((fp1=fopen(oriname,"r"))==NULL)
{ clrscr();
printf("Can not find the special file, try again?[Y/N] [ ]\b\b");
do
{
ch=getche();
if(ch!='y'||ch!='Y'||ch!='n'||ch!='N')
{ clrscr();
printf("Can not find the special file, try again?[Y/N] [ ]\b\b");
}
}while(ch!='n'&&ch!='N'&&ch!='y'&&ch!='Y') ;
if(ch=='y' || ch=='Y')
continue;
else
return;
}
else break;
}
printf("\nTarget file (*.bat): ");
scanf("%s",tarname);
if((fp2=fopen(tarname,"w"))==NULL)
{printf("Can not create the file!!\n");
getch();
return;
}
while(!feof(fp1))
{ ah=fgetc(fp1);
if(ah==10||ah==' ')
continue;
else
break;
}
fprintf(fp2,"@echo off");
fputc(10,fp2);
fprintf(fp2,"echo ");
if(ah=='>'||ah=='^'||ah=='<'||ah=='&'||ah=='|'||ah=='%')
{ if(ah=='>')
{ fputc('^',fp2);
fputc('>',fp2);
}
if(ah=='<')
{ fputc('^',fp2);
fputc('<',fp2);
}
if(ah=='^')
{ fputc('^',fp2);
fputc('^',fp2);
}
if(ah=='&')
{ fputc('^',fp2);
fputc('&',fp2);
}
if(ah=='|')
{ fputc('^',fp2);
fputc('|',fp2);
}
if(ah=='%')
{ fputc('%',fp2);
fputc('%',fp2);
}
}
else
{ if(ah=='')
fprintf(fp2,">>#@$5e8.reg");
else
fputc(ah,fp2);
}
while(!feof(fp1))
{ ah=fgetc(fp1);
if(ah==10)
{
{fprintf(fp2,">>#@$5e8.reg");
fputc(ah,fp2);
}
while(!feof(fp1))
{ ah=fgetc(fp1);
if(ah==10||ah==' ')
continue;
else
break;
}
if(ah=='')
break;
fprintf(fp2,"echo ");
}
if(ah=='>'||ah=='^'||ah=='<'||ah=='&'||ah=='|'||ah=='%')
{ if(ah=='>')
{ fputc('^',fp2);
fputc('>',fp2);
}
if(ah=='<')
{ fputc('^',fp2);
fputc('<',fp2);
}
if(ah=='^')
{ fputc('^',fp2);
fputc('^',fp2);
}
if(ah=='&')
{ fputc('^',fp2);
fputc('&',fp2);
}
if(ah=='|')
{ fputc('^',fp2);
fputc('|',fp2);
}
if(ah=='%')
{ fputc('%',fp2);
fputc('%',fp2);
}
}
else
{ if(ah=='')
fprintf(fp2,">>#@$5e8.reg");
else
fputc(ah,fp2);
}
}
fprintf(fp2,"regedit /s #@$5e8.reg");
fputc(10,fp2);
fprintf(fp2,"del #@$5e8.reg");
fclose(fp1);
fclose(fp2);
}
附件
1: reg2bat.rar (2008-1-14 16:46, 8.8 K,下载次数: 108)
|
|