我目前正在制作一个加密/解密程序。加密后,结果存储在一个文本文件中,每个字符存储为一个十六进制值。 我目前正在解密,第一步是读入该文件,并将每个十六进制值作为一个元素存储在数组中。
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++;
}
我得到的错误信息是
passing argument 1 of 'fgets' makes pointer from integer without a cast
是否可以使用 fgets 实现我想要的?
最佳答案
char *fgets(char * restrict s, int n,FILE * restrict stream);
但是您正在向它传递 int
.. 这就是提示的原因。它甚至说它是
将传递的 int
类型视为 char*
但未提供显式转换。所以它提出了警告。
您可以先读取字符数组中的数字,然后使用 strto*
获取转换后的 int
。
关于C语言 : read in hex from file to populate array,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48368558/