为什么总是返回值为4而不执行decrypt函数?
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void decrypt(const char *file);
int main(int argc,char *argv[])
{
if(argc==2)
{
const char *encryptedfile=argv[1];
decrypt(encryptedfile);
return 0;
}
else
{
printf("%s",argv[1]);
return 4;
}
}
void decrypt(const char *file)
{
FILE *encrypt=fopen(file,"rb");
if(encrypt==NULL)
{
printf("fail to open");
return;
}
char decryptedFilename[100];
strcpy(decryptedFilename, file);
strcat(decryptedFilename, ".dec");
FILE* decrypted = fopen(decryptedFilename, "wb");
if (decrypted == NULL)
{
printf("Failed to create the decrypted file.\n");
fclose(encrypt);
return;
}
int ch;
while((ch=fgetc(encrypt))!=EOF)
{
unsigned char decryptedByte= (ch<<3) | (ch>>5);
decryptedByte^=0xF0;
fputc(decryptedByte,decrypted);
printf("%c", decryptedByte);
}
fclose(encrypt);
fclose(decrypted);
}