0

I am at the point in pset2 Vinegere, where I have to write the shift function. The tutorial (or guidance on the left side in sandbox) is telling me to place the following line of code after the curled brace of main:

int shift(char c)

    {
       // TODO
    }

However, when I tried to compile, I got the answer:

vigenere.c:52:1: error: control reaches end of non-void function [-Werror,-Wreturn-type]
}
^

I tried to fill in the //TODO and came to the following code:

int shift(char c)
{
   for (int i = 0; i < c; i++)
       if isupper(shift)
       {
           printf("%i", (shift-65) % 26);
       }
       else if islower(shift)
       {
           printf("%i", (shift-97) % 26);
       }
       else
       {
           printf("%i", shift);
       }
}

However, this seems not to work either.

Can anybody help me on this please? I can't my mistakes.

Kind Regards,

Nisanth

1

The compile error is because by definition, the function will return an int, but there is no return in the (blank) version. Remember the parts of the function definition:

int: what type the return value will be
shift: the name of the function
char c: the argument the function expects

Since c is a single character, there is no call for a for loop.

This function seems to confuse the function name (shift) with the function argument (c).

You must log in to answer this question.

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