I'm getting undeclared identifier errors for the letter i in the first 3 lines of code below.(Note: I have only posted the second part of the code). My algo is possibly a bit messed up too so far but I am only getting errors for these three lines. Some advice as to a succinct way to declare the 'i's would be good. Is it possible to modify just these lines?

    char original = word[i];
    int num[i];
    char cipher[i];

    if (isalpha (original))  //verify original input not integers
        printf("ciphertext: ");
        num = atoi(argv[1]);  //change original string to integers

        for(int i=0; i<strlen(num[i]); i++) 

            if(isupper(original))  //if original characters are uppercase 
                cipher[i] = (word[i]) - num -65)) % 26 + 65; 
                printf("%c", cipher[i]);

                else (islower(original)) //for lowercase characters
                    char cipher[i] = (original) + num - 97)) % 26 + 97;
                    printf("%c", cipher[i]);

                //other remaining characters
                printf(("%c", (original));  // or print them together

(Incidentally the code is supposed to convert code to numerical then apply a key then print as uppercase characters - confusing.)


Where is i declared before it is used in the first three lines? Based on the usage, I would guess that it should be declared as int i; somewhere before it is used, and initialized to some value.

If this isn't the problem, please edit the question and add the code that precedes the first 3 lines shown.

If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance. ;-)

  • I haven't declared i previous to those lines of code as it wasn't used. That code is most of the program. I tried adding int i; above and further down but then I go from 3 errors to 9 or 11. I received the error: 'over-shadows a local variable' (referring to the three lines of code at the top). – Android1 Mar 10 '17 at 15:27
  • Just because you get more errors doesn't mean you aren't making progress. Sometimes, fixing 1 error reveals more hidden errors that were masked by the original problem. Like any other variable, i needs to be declared and initialized before it is used, and you're definitely using i in those first 3 lines. As for the overshadow warnings, if you redeclare i later, it is creating a second version of i that is shadowing the first. It doesn't need to be redeclared, but you will need to make sure that whatever value is in i is appropriate at that point. OR, you can declare/use a different variable. – Cliff B Mar 10 '17 at 15:41
  • I might try renaming i to something different in each of those three variables - like x, y, z and see if there is progress. So I was using i in those three lines. I thought I was declaring i. I'm new to all this. Thanks. – Android1 Mar 10 '17 at 15:57

You must log in to answer this question.

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