I keep getting an error, and I'm not sure why. For some reason the compiler thinks the char
pointer p
is an integer. The relevant section of my code is:
int main(int argc, char **argv) {
char *p;
FILE *fd = fopen("words.txt", "r");
unsigned char *iv = (unsigned char *)"0000000000000000";
unsigned char *plaintext = (unsigned char *)"This is a top secret";
unsigned char *real_ciphertext = (unsigned char *)"8d20e5056a8d24d0462ce74e4904c1b513e10d1df4a2ef2ad4540fae1ca0aaf9";
//unsigned char key[128];
unsigned char ciphertext[128];
int ciphertext_len;
while ((p = nextword(fd)) != NULL) {
int l;
/* append space characters to key to make sure it is 16 characters long*/
while ((l = strlen(p)) < 16) {
p[l + 1] = ' ';
p[l + 2] = '\0';
}
/* Encrypt the plaintext with the key */
ciphertext_len = encrypt(plaintext, strlen((char *)plaintext), p, iv, ciphertext);
if (strcmp(real_ciphertext, ciphertext) == 0)
printf("The key is:%s", p);
}
EVP_cleanup();
ERR_free_strings();
fclose(fd);
}
//
// gets the next word from the list of words
//
#define MAXWORD 200
// It returns the next word nullterminated from fd.
// If there are no more more words it returns NULL.
unsigned char word[MAXWORD];
unsigned char c;
char *nextword(FILE *fd) {
int wordLength = 0;
while ((c = fgetc(fd)) != EOF) {
if ((c != ' ') && (c != '\n') && (c !='\t') && (c !='\r')) {
word[wordLength] = c;
wordLength++;
} else
if (wordLength > 0) {
word[wordLength] = '\0';
return word;
}
}
if (wordLength > 0) {
word[wordLength] = '\0';
return word;
} else
return NULL;
}
From this code, I compile and get the error:
findkey.c: In function 'main':
findkey.c:25:11: warning: assignment makes pointer from integer without a cast
while ((p = nextword(fd)) != NULL)
findkey.c: At top level:
findkey.c:65:8: error: conflicting types for 'nextword' char *nextword(FILE *fd)
findkey.c:25:13: note: previous implicit declaration of 'nextword' was here while ((p = nextword(fd)) != NULL)