• 0

[C] Typecasting Help


Question

Okay, when I try to compile this with Dev-C++ I get this error on line 29, "invalid operands to binary +".

It is my version of an encryption program, and can be cracked without much effort with a computer, so don't say that my encryption is bad, it's just for practice right now.

#include <stdio.h>

int main(int argc, char *argv[])
{
     if(argc != 2)
     {
          printf("Syntax: %s <filename>", argv[0]);
     }

     int * int_pass;
     int * int_text;
     char * char_pass;
     char * char_text;

     printf("Enter a Password: ");
     scanf("%s", &char_pass);
     int_pass = (int*)char_pass; /* Convert to #'s */

     printf("Enter Text: ");
     scanf("%s", &char_text);
     int_text = (int*)char_text; /* Convert to #'s */

     FILE * makeFile;
     makeFile = fopen(argv[1], "wt");
     
     int encrypted;
     encrypted = int_text + int_pass;
     fprintf(makeFile, "%d", encrypted);
     fclose(makeFile);
     return 0;
}

Link to comment
Share on other sites

1 answer to this question

Recommended Posts

  • 0

Probably because you're trying to add 2 arrays (well, pointers, but same difference). You would have to add each number one at a time. You can't add arrays, especially like you're doing right now. Right now you're just adding addresses.

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.