Friday, May 1, 2009

Optimization to password.c

So, after a long time, atleast one of my friends came up with a couple of optimizations and an error for me to correct. The first error is that in the code at the end of the do-while statement, the comparison of counter to a number is not at all clear, so, here is what it should look like

while(counter<500); ----> this is to limit the number of characters in the string.

One of them is rather trivial. The initialization of the variable counter is not necessary as it is a global variable and will automatically be initialized to '0' at runtime.

A couple of good optimizations suggested by Barjatiya were as follows:
1. Instead of "goto end:", he says, I could have used a break. But I insisted that I like goto, and so he left me alone.

2. The other was instead of printing all the characters using a printf, I could rather converts the character array to a string and then print the whole thing. One problem was encountered that way, which again, thanks to baddu, I was able to correct it.


Note: Because of the html tags "<" and ">" , printing the code is a headache, and hence comparisons, and #include ...... will not work, If you copy paste the code. (Still trying to figure out someway.)

Second program, will be coming very soon. Keep checking.
Adios!