New answers tagged

0

Strings are immutable. That means that when they are declared, the memory allocated to them cannot be changed. You can put a shorter string in that memory, but not a longer one because it will overwrite other memory allocated elsewhere. When plaintext is declared in the second code snipet, it has exactly one byte allocated to it, to hold the end of string ...


1

You have a structural problem. You're trying to create main(), followed by a function called is_valid_key), but you have some errors in how you did it. The main() function (yes, it's technically a function, with a special name) should end with a closing curly brace, before the start of any other functions. This code has the closing curly brace at the very ...


1

If code generates a seg fault, something is definitely wrong, period! End of story! Common newbie error. The code is trying to do something with argv[1] before verifying that argc == 2, and by extension, before verifying that argv[1] exists. Simply put, if there's no key, then argc = 1. That means that argv[1] doesn't exist. So, when the code tries to use ...


1

Look at this line: for (int i = 0; i < strlen(argv[i]); i++) Here you're trying to iterate over all arguments in the command line when you should iterate only over the second argument. To fix this you can create a variable: string x = argv[1]; for (int i = 0; i < strlen(x); i++) or use the address: for (int i = 0; i < strlen(&argv[1][i]); i++)...


Top 50 recent answers are included