需要一个关于 easyzlib 的示例(如何压缩和解压缩从命令行 Windows/Linux 中发送到 argv 中的字符串)
好的,现在已经完成一半了,这就是我所做的:
`int main(int argc,char* argv[]){
FILE *inputFile,*outputFile;
unsigned char *inputBuffer, *outputBuffer;
unsigned char *readMod = "r";
int result,x;
long int outputSize;
long int outputSizeun;
size_t inputSize;
if(argc >= 3){
inputFile = fopen(argv[2],readMod );
// get length of input
fseek(inputFile, 0, SEEK_END);
inputSize = ftell(inputFile);
fseek(inputFile, 0, SEEK_SET);
//allocate the inputBufer size
inputBuffer = (unsigned char *)malloc(inputSize);
fread(inputBuffer, 1, inputSize, inputFile);
outputSize = EZ_COMPRESSMAXDESTLENGTH(inputSize);
//allocate the outputBuffer size
outputBuffer = (unsigned char *)malloc(outputSize);
//check for the -z(compression)/-u(decompression) option s
if(strcmp("-z",argv[1])==0){
result = ezcompress(outputBuffer, &outputSize, inputBuffer, inputSize);
}else if(strcmp("-u",argv[1])==0){
result = ezuncompress(outputBuffer, &outputSizeun, inputBuffer, inputSize);
}else{
printf("Error : unknown operation \" %s \" type -z for compression or -u for decompression\n",argv[1]);
}
if (result == 0) {
// if the output filename was not present it output the compressed data into a file named "compress"
if(argv[3] == NULL){ argv[3] = "output";}
//write the output
outputFile = fopen(argv[3], "w");
fseek(outputFile, 0, SEEK_END);
fseek(outputFile, 0, SEEK_SET);
fwrite(outputBuffer, 1, outputSize, outputFile);
fclose(outputFile);
} else {
// Something went wrong
printf("%d ",result);
}
//now freeing buffers
free(inputBuffer);
free(outputBuffer);
}else{
printf("insufficnt Arguments :-s");
return 1;
}
return 0;
}
为什么当我运行 **a.exe -u 输出时此代码返回 -3
OK now am half the way ,This is what i've done:
`int main(int argc,char* argv[]){
FILE *inputFile,*outputFile;
unsigned char *inputBuffer, *outputBuffer;
unsigned char *readMod = "r";
int result,x;
long int outputSize;
long int outputSizeun;
size_t inputSize;
if(argc >= 3){
inputFile = fopen(argv[2],readMod );
// get length of input
fseek(inputFile, 0, SEEK_END);
inputSize = ftell(inputFile);
fseek(inputFile, 0, SEEK_SET);
//allocate the inputBufer size
inputBuffer = (unsigned char *)malloc(inputSize);
fread(inputBuffer, 1, inputSize, inputFile);
outputSize = EZ_COMPRESSMAXDESTLENGTH(inputSize);
//allocate the outputBuffer size
outputBuffer = (unsigned char *)malloc(outputSize);
//check for the -z(compression)/-u(decompression) option s
if(strcmp("-z",argv[1])==0){
result = ezcompress(outputBuffer, &outputSize, inputBuffer, inputSize);
}else if(strcmp("-u",argv[1])==0){
result = ezuncompress(outputBuffer, &outputSizeun, inputBuffer, inputSize);
}else{
printf("Error : unknown operation \" %s \" type -z for compression or -u for decompression\n",argv[1]);
}
if (result == 0) {
// if the output filename was not present it output the compressed data into a file named "compress"
if(argv[3] == NULL){ argv[3] = "output";}
//write the output
outputFile = fopen(argv[3], "w");
fseek(outputFile, 0, SEEK_END);
fseek(outputFile, 0, SEEK_SET);
fwrite(outputBuffer, 1, outputSize, outputFile);
fclose(outputFile);
} else {
// Something went wrong
printf("%d ",result);
}
//now freeing buffers
free(inputBuffer);
free(outputBuffer);
}else{
printf("insufficnt Arguments :-s");
return 1;
}
return 0;
}
why does this code returns -3 when i run **a.exe -u output
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
ezcompress 和 ezuncompress 直接处理表示为字符数组的文件数据。
ezcompress and ezuncompress work on the file data directly which are represented as arrays of characters.