Alright. I assume you posted this to get our opinion, so:
1. Standard compliance
Line 3: Unlearn conio.h. It's non-standard, it's old, and different compilers implement it however they want, if at all.
Line 48: void main() is illegal. Never use it. The only legal forms of main() are int main() and int main(int argc,char **argv). Chose the former if you don't need command line arguments, choose the latter if you do.
2. Coding style.
Unlike most newbies I've seen, you seem to already have a more or less consistent style, but I have some things to nitpick.
Line 37: You should learn the precedences of operators to avoid having to use all those unnecessary parentheses. They don't hurt, but they could potentially make your expressions harder to read. The condition could be rewritten as
(op=='d' || op=='D')
.
Avoid whenever possible (which is to say, always) for if, while, and for, having the block on the same line as the structure header. It makes code considerably harder to read. Compare
if ((op=='d')||(op=='D')) key=-key;
to
1 2
|
if ((op=='d')||(op=='D'))
key=-key;
|
Line 39: This is less serious, but avoid unnecessary casts. The condition can be rewritten as
(c+key<=255)
. The code compiles to exactly the same, but it's easier to read. Likewise, the return statement could be
return c+key-223;
I'm a little dichotomic on the next point. On one hand, checking for impossible conditions is absurd, but on the other, a bug in the algorithm can'r be ruled out. There are things that is of course absurd to check, such as whether a%b<b, bu there are many others, particularly when it comes to user input, that isn't. You should use your judgement for each case.
Lines 106-120: You should always brace non-trivial blocks. For example, can you tell which if the else belongs to?
1 2 3 4 5 6
|
if ()
for ()
if ()
//...
else
//...
|
There's also a problem with your indentation. It would seem to suggest that you meant for all those lines to be inside the for, but the syntax says otherwise.