I'm reading a file and I want to apply XOR encryption to it and print it.
This is my code
Code:
#include <stdio.h>#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/stat.h>
#define XOR_KEY0x6F
int main() {
FILE *infp;
char buf[1024];
infp = fopen("test.txt", "r");
while ((fgets(buf, sizeof(buf), infp)) != NULL)
{
printf("Contents: %s", buf ^ XOR_KEY);
}
return 0;
}
I get this error:
error: invalid operands to binary ^ (have 'char *' and 'int')
17 | printf("Contents: %s", buf ^ XOR_KEY);
| ~~~ ^
| |
| char *
I tried to encrypt an initialized char array and it worked, but why am I not able to do this to char buf[1024] array?
Thanks