C-数组比较-读取文件中的字符串转换为16进制字符串

    unsigned char pp[] = { 0xF1, 0x20, 0xE4, 0x03, 0xF0, 0x20, 0xE6, 0x8A, 0x76, 0x69, 0x39, 0xC5, 0xEE, 0x3C, 0xEA, 0x5A, 0xA2, 0xA1, 0xD1, 0xA4, 0x2D, 0x7F, 0xC9, 0x62, 0xDD, 0x38, 0x51, 0x5A, 0xBB, 0x56, 0x40, 0x1A, 0xAC, 0xFB, 0xF8, 0x68, 0x90, 0x93, 0xC8, 0x83, 0x87, 0xD7, 0x31, 0x8F, 0x20, 0x17, 0xCB, 0x67, 0x4C, 0x0A, 0x7D, 0x34, 0xF3, 0xFE, 0xF5, 0xC6, 0xFE, 0x83, 0x2C, 0x0C, 0x29, 0x0D, 0x47, 0xEB, 0x19, 0x94, 0x43, 0x9C, 0xF0, 0x97, 0xAF, 0x78, 0x64, 0xFE, 0xDF, 0x2D, 0xE0, 0x9E, 0xC0, 0xC5, 0xED, 0xE8, 0xCF, 0xA5, 0x7D, 0x7C, 0x06, 0xBC, 0x42, 0x1E, 0xD0, 0x52, 0x7C, 0xE7, 0x8F, 0x3A, 0x23, 0x0F, 0x99, 0x0A, 0x24, 0xA3, 0x17, 0x34, 0xD8, 0x53, 0xDC, 0xF6, 0x34, 0x5F, 0x51, 0xF2, 0x62, 0x2E, 0xF6, 0xB8, 0x5E, 0xC7, 0xD2, 0xE0, 0xAF, 0x22, 0x7D, 0x08, 0x91, 0xD6, 0x97, 0x9C };

    unsigned char p1[] = { 0xF1, 0x20, 0xE4, 0x03, 0xF0, 0x20, 0xE6, 0x8A, 0x76, 0x69, 0x39, 0xC5, 0xEE, 0x3C, 0xEA, 0x5A, 0xA2, 0xA1, 0xD1, 0xA4, 0x2D, 0x7F, 0xC9, 0x62, 0xDD, 0x38, 0x51, 0x5A, 0xBB, 0x56, 0x40, 0x1A, 0xAC, 0xFB, 0xF8, 0x68, 0x90, 0x93, 0xC8, 0x83, 0x87, 0xD7, 0x31, 0x8F, 0x20, 0x17, 0xCB, 0x67, 0x4C, 0x0A, 0x7D, 0x34, 0xF3, 0xFE, 0xF5, 0xC6, 0xFE, 0x83, 0x2C, 0x0C, 0x29, 0x0D, 0x47, 0xEB, 0x19, 0x94, 0x43, 0x9C, 0xF0, 0x97, 0xAF, 0x78, 0x64, 0xFE, 0xDF, 0x2D, 0xE0, 0x9E, 0xC0, 0xC5, 0xED, 0xE8, 0xCF, 0xA5, 0x7D, 0x7C, 0x06, 0xBC, 0x42, 0x1E, 0xD0, 0x52, 0x7C, 0xE7, 0x8F, 0x3A, 0x23, 0x0F, 0x99, 0x0A, 0x24, 0xA3, 0x17, 0x34, 0xD8, 0x53, 0xDC, 0xF6, 0x34, 0x5F, 0x51, 0xF2, 0x62, 0x2E, 0xF6, 0xB8, 0x5E, 0xC7, 0xD2, 0xE0, 0xAF, 0x22, 0x7D, 0x08, 0x91, 0xD6, 0x97, 0x9C };
    memset(p1, 0, 128);

    // 拷贝到p1
    memcpy(p1, Z->P->d, 128);

    // 比较
    for (int i=0;i<128;i++)
    {
        if (p1[i] != pp[i]) {
            printf("=============================error happen====================================\n");
            char name9[] = "error p";
            myprintf(name9, p1, 128);
            // 退出当前进程  
            exit(1);
        }


    }

如果字符串为 64 则MAX_LINE_LENGTH应该   为 65

比如data.txt中有:

DDBA692850589B1B6A0636964FF3A46C88DE153C8E1D46065FA01EC5A046002E

 #define MAX_LINE_LENGTH 65

  FILE* file;
    char line[MAX_LINE_LENGTH];
   int arrayLength = 32;

   unsigned char expPrivateKey[32] = { 0 };

    // 打开文件  
    file = fopen("D:\\data.txt", "r");
    if (file == NULL) {
        printf("无法打开文件\n");
        return 1;
    }

    逐行读取文件内容  
    while (fgets(line, MAX_LINE_LENGTH, file)) {
        printf("%s", line);
    }

    printf("\n");

    for (int i = 0; i < arrayLength; i++) {
        sscanf_s(&line[i * 2], "%2hhx", &expPrivateKey[i]);
    }
    printf("\n");
 
    for (int i = 0; i < arrayLength; i++) {
        printf("%02X", expPrivateKey[i]);
    }
   

你可能感兴趣的:(C语言,c语言,开发语言)