C解密程序

C decryption program

当我编译程序并运行它时,它没有打印任何东西。我相信问题是暂时的,但我不明白出了什么问题。它应该将十六进制转换为 ASCII,然后是加密的消息。

    #include<stdlib.h>
    #include<stdio.h>
    #include<string.h>
    int main(int argc, char **argv) {
         int p;
//Opening a file
         FILE*tp; 
             tp = fopen(argv[1], "r");
            if(tp == NULL)
         {
            printf("Error opening file!\n");
            return 0;
         }
         else
         {
//Decryption code
            while((p=fscanf(" %x",&p))!=EOF)
            { 
            p=p >> 2;
            p=p - 200;
            printf(" %c",p);
            }
         }
        return 1;
        fclose(tp);
    }

看起来您需要指定文件指针 "tp" 并将其提供给 fscanf 函数。

fscanf() returns 成功匹配和分配的输入项数,而不是输入项本身。另外,如上所述,您需要将文件指针传递给函数。试试这个:while(fscanf(tp, "%x", &p) != EOF)