【问题标题】:C language: read in hex from file to populate arrayC语言:从文件中读取十六进制以填充数组
【发布时间】:2018-06-30 07:34:14
【问题描述】:

我目前正在制作一个加密/解密程序。加密后,结果存储在一个文本文件中,每个字符存储为一个十六进制值。 我目前正在解密,第一阶段是读取该文件,并将每个十六进制值存储为数组中的一个元素。

FILE * decryptIn = fopen("output.txt", "r");
fseek(decryptIn, 0L, SEEK_END); //counts the amount of bytes from start to end of file
int fileSize = ftell(decryptIn); //stores the size of the file in bytes
rewind(decryptIn); //sets offset back to 0 (back to start of file)

int *decryptHexArray = malloc(sizeof(int)*5*fileSize);
int currentPointer;
int counter = 0;

while(fgets(decryptHexArray[counter], fileSize, decryptIn)) //loop that reads each string from the file
{
    counter++;
}

我得到的错误信息是

传递 'fgets' 的参数 1 使指针从没有 a 演员表

是否有可能用 fgets 实现我想要的?

【问题讨论】:

标签: c hex fgets


【解决方案1】:

char *fgets(char * restrict s, int n,FILE * restrict stream); 但是您将int 传递给它.. 这就是抱怨的原因。它甚至说它是 将传递的int 类型视为char*,但没有提供显式转换。所以它提出了警告。

您可以先读取字符数组中的数字,然后使用strto* 得到转换后的int

【讨论】:

    猜你喜欢
    • 2015-05-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-09
    • 1970-01-01
    • 2012-04-04
    • 2020-10-25
    • 2012-09-15
    • 1970-01-01
    相关资源
    最近更新 更多