48.c

来自「《C语言实战105例》,一些常用的c语言源代码」· C语言 代码 · 共 49 行

C
49
字号
#include <dos.h>
#include <stdio.h>
#include <string.h>
void EncryptBat(char *filename)
{
	char *pointer,*data;
	FILE *fp;
	int length,i;
	fp=fopen(filename,"rb+");
	if (fp==NULL)
	{
		printf("open file %s error\n",filename); 
		return 0;
	}
	else
	{
		fseek(fp,2,SEEK_END);
		length=ftell(fp);
		data = ( char *)calloc((unsigned)length,sizeof( char ));
		if ( !data )
		{
			printf("runtime error!");
			return 0;
		}               
		rewind(fp);
		i=0;
		while(!feof(fp))
			data[i++]=fgetc(fp);
		while(pointer = strrchr(data,'\n'))
			strnset(pointer,0,1);
	}  
	printf("encrypt file successfully!\n");
	rewind(fp);
	fwrite(data,1,length,fp);
	fclose(fp);                          
}
int main()
{
	char filename[20];
	clrscr();
	printf("*******************************************\n");
	printf("| This program will encrypt the .bat file |\n");
	printf("*******************************************\n");
	printf("Please enter the filename to encrypt:\n");
	scanf("%s",filename);
	EncryptBat(filename);
	getch();
	return 0;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?