0

I need some help with my debugging for the caesar cipher. I get these errors.

[image replaced with actual errors produced by the code that follows]

caesar.c:25:17: error: incompatible integer to pointer conversion assigning to
      'string' (aka 'char *') from 'int' [-Werror,-Wint-conversion]
            key = atoi(argv[1]);
                ^ ~~~~~~~~~~~~~
caesar.c:41:54: error: invalid operands to binary expression ('string'
      (aka 'char *') and 'int')
                printf("%c" , ((plaintext[i]-97+ key)%26-97));
                               ~~~~~~~~~~~~~~~~~~~~~~^~~
caesar.c:45:54: error: invalid operands to binary expression ('string'
      (aka 'char *') and 'int')
                printf("%c" , ((plaintext[i]-65+ key)%26-65));
                               ~~~~~~~~~~~~~~~~~~~~~~^~~

I just need to know how to solve these errors.

Here's my code below:

[code removed per academic honesty policy]

1 Answer 1

0

All the errors are caused by the same thing. You are declaring key as a string (aka char*) aka a pointer, and then you use it as an integer.

1
  • Great, but how do you fix that? How do you convert your pointer string "key" to an integer? Do you just declare it right there? so ((plaintext[i]-97+ int key)%26-97));?
    – spink
    Commented Nov 12, 2015 at 18:02

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .