Subj : Re: simple c/c++ programming question about encryption To : comp.programming From : Sc0rpi0 Date : Tue Jul 05 2005 05:03 am > [...] It goes through the code one full > time (and updates the counter) before asking for user input - thus it > updates the counter twice for every one input. Since I'm not so > familiar with C, can anyone explain this to me. The same program works > perfectly with C++, which is why I don't understand this. > scanf("%c", &originalLetter); > > if(originalLetter >= '!' && originalLetter <= '~' && k < 93 && k >= > 0){ > encryptedLetter = BASE+(originalLetter-BASE+k)%RANGE;/*the > calculation*/ > printf("The encrypted character is %c.\n", encryptedLetter); > /*Output */ > } > counter = counter + 1; Because scanf reads '\n' characters (end of line) from previous inputs, so you're getting '\n',user_input,'\n',user_input, etc. '\n' usually is <'!' - encryption does not catch that, but counter is updated. In C++ you use streams so it is not reading the chars the same way as in C and program is NOT THE SAME ;) -- Sc0rpi0 I hated going to weddings. All the grandmas would poke me saying "You're next". They stopped that when I started doing it to them at funerals. .