![]() |
|
[C] my code snippet not giving correct output - Printable Version +- Hack Forums (https://hackforums.net) +-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444) +--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151) +---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118) +---- Thread: [C] my code snippet not giving correct output (/showthread.php?tid=5746693) |
my code snippet not giving correct output - kakarot007 - Nov 2, 2017 Hello i have a encrypted message with key that was used to encrypt it . I want to reverse it . first i have this java snippet which works completely fine and gives correct answer too . encrypted message : Bjj rwkcs dwpyp fwz ovors wxjs vje tcez fqg plain text : The quick brown fox jumps over the lazy dog Code static String decrypt(String input) {now i am tryint to do same in C++ below is my code : Code #include <iostream>now the output of my code is : Thh8mrfxr9bunwn8dux8ovors:opbk2thc8oxdy9doe i did everything same , don't know why the wrong output . RE: my code snippet not giving correct output - 0xDEAD10CC - Nov 2, 2017 This is not equivalent: Code if (isalpha(c) || isspace(c))Why are you using isspace()? RE: my code snippet not giving correct output - kakarot007 - Nov 4, 2017 (Nov 2, 2017 01:16 PM)0xDEAD10CC Wrote: This is not equivalent: because spaces are ignored by isalpha() . i want both alphabets and spaces to be recognised . if the letter is alphabet or space enter the if section . RE: my code snippet not giving correct output - 0xDEAD10CC - Nov 4, 2017 (Nov 4, 2017 02:51 AM)kakarot007 Wrote: because spaces are ignored by isalpha() . i want both alphabets and spaces to be recognised . if the letter is alphabet or space enter the if section . You definitely missed the point: https://msdn.microsoft.com/en-us/library/system.char.isletter(v=vs.110).aspx That's not what char.IsLetter is equivalent to. How do you assume this is equivalent code if you obviously don't read documentation? :/ RE: my code snippet not giving correct output - kakarot007 - Nov 6, 2017 (Nov 4, 2017 01:49 PM)0xDEAD10CC Wrote: You definitely missed the point: https://msdn.microsoft.com/en-us/library/system.char.isletter(v=vs.110).aspx Damn :( . you are right . What's equivalent of isLength in c++ ? RE: my code snippet not giving correct output - 0xDEAD10CC - Nov 6, 2017 Simply isalpha() without isspace(). Lastly, you didn't pay close enough attention to your braces or how control conditional statements work that don't have braces. Only the line after is used... Code string decrypt(string encrypted_message)RE: my code snippet not giving correct output - HiddenEyE - Nov 6, 2017 this thread just reminded of range based for loop in encryption and decryption. will try to do this with my encryption |