Hot answers tagged

2

I don't know where you are on the "comfortable" spectrum, but I will assume that you're closer to "more" since you are trying this and you are using const. I hope I can explain it adequately. This statement const string stringToBeEncrypted = GetString(); is declaring that you cannot change the value of stringToBeEncrypted, which is a char pointer. It is not, ...


1

You can just go ahead and treat it as an integer. If, for example, plaintext="bar", plaintext[0]=b=98, and you can just perform operations with it, such as plaintext[0]+1, which will yield 99.


1

Your code reads from the outside of cipher which contains unknown values because your cipher is not terminated by \0. Here is the link that you can debug memory errors or unexpected behavior in the future. The instruction for other C psets. I copy & pasted the error message here. Memory access error: reading from the outside of a memory space; ...


1

You've run into a common newbie problem. The issue lies in this code: if ( isalpha ( c ) != 'true' ) The issue is with the return value of isalpha and what you're comparing it to. Let's handle the latter first. Putting true in single quotes is a problem. I'm not even sure what that will evaluate to. IF you want to compare something to true or false, ...


1

I am not a Pro, too, but the first thing I see is the "isalpha(c) != "true" -> When I recall this pset correctly, isalpha() does not return "false" or "true" but 0 or 1. But if the statement would be wrong the compiler would complain. So it must be a logical issue. However, that would be my first approach to solve this. Currently it looks like (at least for ...


1

In c, chars are essentially smaller ints. They have just enough bits to accomodate all ASCII symbols. You can add, subtract, multiply, divide, and % or mod, chars. For instance, printf("%c", 'a'-' ') should print 'A' each char corisponds to their ASCII number. So before doing that math you first need to convert 'A' or 'a' to 0. I hope that helps.


Only top voted, non community-wiki answers of a minimum length are eligible