1

I'm trying to iterate repeatedly over key (a word) which the user inputs on the command line. This keyword is used to encipher a word which the user inputs when prompted by the word 'plaintext'. I have to cycle over the letters in the key, while enciphering the plaintext word. I'm getting the errors:

incompatible pointer types passing 'char **' to parameter of type 'const char *'; dereference with * [-Wincompatible-pointer-types]

/usr/include/string.h:82:28: note: passing argument to parameter '__s' here
size_t   strlen(const char *__s); 

I'm confused as to how to iterate through integers, which appears to be necessary where ASCII is concerned where the input key are not integers. At least I think that's the problem. Some help would be appreciated.

int main(int argc, char* argv[])
{

if (argc<2) //re key entered on command line
{
    printf("Please enter your word key"); 

    return 1;
}

int key = atoi(argv[1]);  

if(argc>=2)
{
    printf("plaintext:");      
    char* word = GetString();  

    printf("ciphertext:");   

    do
    {  //starts loop to iterate through the letters in the key

        for(int l=0; l<strlen(argv); l++)//iterate over key letters
        {
            int num=l;

            for(int i=0; i<strlen(word); i++) //iterates through word entered by user as plaintext
            {

1 Answer 1

2

The error comes from here:

for(int l=0; l<strlen(argv); l++)

Think about it. strlen() wants a const char* or char*. You gave it argv, which is an array of the command line arguments. Because argv is an array, strlen will not accept it and throws an error.

A simple fix would be to replace argv with key since you are going to be iterating over the key's letters.

If you still have issues/questions, comment down below.

2
  • I changed that as you suggested then I received an error at the line int key = atoi(argv[1]); I changed that line to char* key = (argv[1]) as well and now those errors have gone away. Thanks for your help.
    – Android1
    Commented Mar 15, 2017 at 12:15
  • No problem, I'm glad it helped you. :-) Commented Mar 15, 2017 at 12:26

You must log in to answer this question.

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