1
    // k is between 1 and 26
    for (int i = 0, n = strlen(s); i < n; i++)
    {
        // only for capital letters
        if (s[i] >= 'A' && s[i] <= 'Z')
        int dif = 'Z' - s[i];     //// how far is s[i] to Z ?
        // to understand if we need to go through Z to A
        if (k > dif)
        {
            k -= dif;
            // this step includes A in the counting process as well because we need to count k -= dif number from Z and this isn't possible to my logic
            s[i] = 'A' + (k-1);
        }
        // if the transformation of letters is completed withouth needing to go through Z to A
        else
        {
            s[i] = (k);
        }
    }
caeser.c:29:13: error: expected expression
        int dif = 'Z' - s[i];     //// how far is s[i] to Z ?
        ^

caeser.c:31:21: error: use of undeclared identifier 'dif'; did you mean 'div'? if (k > dif)

That's a part of my code for which I get an an error in the line: int dif .... and in the following lines because of "undeclared identifier" normally. The error is called "expected expression". That's the first time that I'm declaring a variable called dif and 'Z' - s[i] should be cast to int automatically, as far as I understood. Why am I having this error ?

1

I only needed to add some extra braces for the if condition beneath the for loop.

0

Can you copy and paste the exact error? (Code format, error will show line and place and maybe more detail)

undeclared identifiers will come when you forget to do

include

include at the top of your file.

2
  • I think the undeclared identifier error is because of the first error, so I'm trying to fix that one. caeser.c:29:13: error: expected expression int dif = 'Z' - s[i]; //// how far is s[i] to Z ? ^ caeser.c:31:21: error: use of undeclared identifier 'dif'; did you mean 'div'? if (k > dif) – Ali Sarp Mestcioglu Dec 29 '17 at 11:21
  • and there is a little green thing beneath i in the expression "expected expression int dif =... I did copy and paste the error in the question – Ali Sarp Mestcioglu Dec 29 '17 at 11:23

You must log in to answer this question.

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