1

The Program has no errrors when checking with check50 but when i check vigenere.c with style50 by:

style50 2015.fall.pset2.vigenere vigenere.c

it gives the following error:

:( 84:20  Too much whitespace after "alphabet". Expected: 0, found: 1.
:( 90:20  Too much whitespace after "alphabet". Expected: 0, found: 1.

The function where this error occurs is as follows:

int key_gen(char alphabet)
{
    int key;

    // key for upper case letters
    if (isupper(alphabet))
    {
        key = (int) alphabet - 'A';
    }

    // key for lower case letters
    if (islower(alphabet))
    {
        key = (int) alphabet - 'a';
    }
    return key;
}

Note

I have already tried removing the space after alphabet and then i get the following error:

:( 84:29  Not enough whitespace after "-". Expected: 1, found: 0.
:( 84:20  Too much whitespace after "alphabet". Expected: 0, found: 1.
:( 90:28  Not enough whitespace before "-". Expected 1, found: 0.
:( 90:28  Not enough whitespace after "-". Expected: 1, found: 0.

I want to ask, if my code is styled according to standards or not. Although the program itself passes the check50 test :)

2

Consider removing the typecasting, because it is essentially redundant. A char is a one-byte integer; the system does it's own internal "casting". Perhaps rewatch the caesar walkthrough. Starting around 4:45 Zamyla discusses ascii math.

1
  • Thanks it helped me, and i understand type casting much better now :)
    – Akhil
    Oct 7 '16 at 14:17
2

Change (int) alphabet to ((int) alphabet).

The parentheses won't change the meaning (as typecast has higher precedence than binary minus operator), but they silence style50 (and are my preferred style for typecasts).

1

Interesting question. In my opinion, your code is correctly styled.

Both of the other answers provide a solution to the problem. But, the real problem is style5050 itself. Again, in my opinion, this is the rare case where style50 doesn't know how to correctly handle this.

If you put parentheses around the cast and the var, as blauef suggested, it quiets check50, but to me, doesn't look as elegant.

If you remove the typecast, as DinoCoderSaurus suggests, it also quiets style50. This is actually what I would do, since I agree with Dino and don't see the typecast as necessary. I actually wish that style50 could suggest this, but that's beyond the capabilities of the program. Also, this would be a coding change, not a style change, and this could arguably be said to be correct or not.

Finally, as proof that style50 is not infallable, if you remove the space that it dislikes, it tells you that there should be a space there, before the '-', so which is right???? ;-) This is a case where it appears to have two rules that conflict.

Thus, my original statement. The style was right. Try varying the code as suggested as well as some of your own changes on this and see what style50 says! It also proves that sometimes, you need to know on your own what is better. Until you confidently know for yourself, you should continue to use style50 to check your code. ;-)

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

You must log in to answer this question.

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