// 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 ?