0

I am currently making an encryption/decryption program. After encryption, the result is stored in a text file, with each character stored as a hex value. I am currently working on the decryption, and the first stage is to read in that file, and store each hex value as an element in an array.

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++;
}

The error message I am getting is

passing argument 1 of 'fgets' makes pointer from integer without a cast

Is it possible to achieve what i want with fgets?

rubicks
  • 4,912
  • 1
  • 30
  • 41
  • well with hex you can also have `A` so i think its better to just use a `char` array – JoshKisb Jan 21 '18 at 15:47
  • Consult this: https://stackoverflow.com/questions/18693841/read-contents-of-a-file-as-hex-in-c ; you'll need `strtoul` http://en.cppreference.com/w/c/string/byte/strtoul – rubicks Jan 21 '18 at 15:48
  • How are the hexdecimal values delimited? Can you assume whitespace-separation? Is there a leading `0x` before each number? – rubicks Jan 23 '18 at 15:25

1 Answers1

3

char *fgets(char * restrict s, int n,FILE * restrict stream); But you are passing an int to it.. that's why the complain. It even says that it is considering the passed int type as char* but there is no explicit casting provided. So it raised the warning.

You can read the number in a char array first then use strto* to get the converted int.

user2736738
  • 30,591
  • 5
  • 42
  • 56