8
votes
How to Wrap Around Array Indexes?
and welcome to the SE community. As for your question, here goes the answer:
This is really simple, to do so, use the modulus operator, i.e. the % operator.
Te modulus operator returns the remainder ...
8
votes
Accepted
How to Handle "rejects "Hax0r2" as keyword" in Vigenere?
The pset says:
If your program is executed without any command-line arguments, with more than one command-line argument, or with one command-line argument that contains any non-alphabetical ...
6
votes
Accepted
Incompatible pointer types error vignere
int c = strlen(argv); strlen(a_string) takes a string as an argument. You have used argv as an argument, an array of strings. If you wanted to get the length of a particular string in the array, for ...
5
votes
How to Wrap Around Array Indexes?
Usually the remainder operator (i.e., %) is used for wrapping around something. The reason is simply because, mathematically, the remainder of dividing an integer a over an integer b is from 0 to b - ...
5
votes
Accepted
Why does my vigenere not pass check50 although it gives the correct output?
You must include "\n" at the end of the encrypted line.
This goes for all the C psets.
5
votes
Accepted
Pset2 Vigenere 'szz' instead of 'rby'
world, say hello!
bazba zba zbazb
=================
xoqmd, rby gflkp!
You are doing this:
world, say hello!
bazbazbazbazbazb
=================
xoqmd, szz gflkp!
You are correctly skipping ...
4
votes
pset2 (vigenere) - Check50 error problems
This is a very common error. You've forgotten to include a control character in your output, and it's not showing up in the message from check50 in Terminal because it's a non-printing character.
It'...
4
votes
Accepted
Vigenere cipher coding drama!
While I haven't tested it, most of your code looks on target at first glance. However, you have a serious problem:
for (k = 0, n = (keyword[k] % strlen(keyword)); k < n; k++)
Your goal is to wrap ...
4
votes
Accepted
PSET 2 - Vigenere: How do I wrap around my key to the plaintext?
Well, I'll try to push you in the right direction without giving away the store here.
You say that you understand that you need to use a different index for the key and the plaintext, yet you are ...
4
votes
extra characters in Vigenere pset2 2016
First, notice that the check50 result and your result have different nonsense characters at the end.
Recall from the Week 2 Lecture "More on Strings" (starting around 1:18) the discussion about ...
4
votes
Accepted
vigenere sometimes prints extra characters at the end of ciphertext in an unpredictable pattern
The problem comes because cipher is declared a char array here char cipher[strlen(plain)];, but printed out using a string (aka char*) format here printf("ciphertext: %s\n", cipher);.
Remember, the ...
3
votes
pset2 (vigenere) - Check50 error problems
Looks like you just forgot to print a trailing "\n". Your program should output the encrypted message and a trailing newline character.
3
votes
Accepted
Vigenere Cipher Doesn't Work Properly
Youre mingling things up a little bit, so I suggest you take some fresh air and let your code be more open, for example, change the way you try to print and cipher everything at the same time, use a ...
3
votes
Accepted
Pset2- Vigenere - Segmentation Fault
As far as I can see, the problem lies in if(!isalpha(argv[i])). argv[] is a string of strings. It seems that you wish to access individual elements of second element in argv. If that's the case, then ...
3
votes
Accepted
pset2 vigenere error "incompatible integer to pointer conversion"
The types char, short, int, long int, and long long int are often referred to as integer types.
Per its manual, the function atoi takes a value of type const char *. I assume your variable named k is ...
3
votes
Accepted
Pset2- Vigenere: returning error on BaRFoo only
This is a common mistake. Your code requires that the plain text to be encoded and the key are both the same case. You haven't allowed for the scenario where one is uppercase and the other is ...
3
votes
Accepted
Vigenere cipher: how to loop the key
First of all it might be better for you if you assigned argv[1] to a string variable called keyphrase for example:
char* keyphrase = argv[1];
Now say keyphrase is "bacon". It would be like that:
...
3
votes
Accepted
wrap around the keyword, vigenere
Look at your tests on the key. Here's one of them:
if (isupper(argv[1][c]))
When you encode a letter, you apply the modulo operation correctly to the key to get the right character, but when you are ...
3
votes
Accepted
Vigenere fails "world, say hello" with "baz" and "BaRFoo" with "BaZ"
Without digging deep into your code, I see two significant problems. They also happen to be the two most common errors on this pset. First, the code uses the same index, i, for both the plain text and ...
3
votes
Accepted
3
votes
Accepted
pset 2 vigenere at a loss
Firstly there are two compilation errors, that will prevent your code from even compiling (making me wonder whether you submitted a different version of your program to the check50).
The first one is ...
3
votes
Accepted
Vigenere -Isalpha only checking first char of key
Both clauses of the if/else contain return statements. When a return statement is encountered, it will immediately return control to the calling program with no further processing in the current ...
3
votes
Accepted
cs50/pset2/vigenere: Code works but check50 rejects 2 item
You are printing garbage values in the final printf statement:
printf("ciphertext: %s\n", cipher); //printing of ciphered text
You are asking it to print cipher as a string. You declared cipher as ...
3
votes
Accepted
Vigenere Segmentation understanding
This is a very, very common error for new programmers. The problem is the actual call to isalpha(). The isalpha() function takes a single char as input, but argv[1] is a string, not a char. Simply ...
3
votes
Why does the if else conditional give me a segmentation fault
First issue is that you blindly get argv[1] before actually checking the number of arguments. The segfault, however, comes from the fact you are passing a string to isalpha, whose argument is actually ...
3
votes
Accepted
Pset 2 Vigenere Increment Problem
This is a common error on this pset. The code needs two independent index variables to track the position within the plaintext and the key. You have two vars, i and cLength, but they are not ...
2
votes
Failing one test case with check50 on pset2 - encrypts "say" to "szz" instead of "rby"
2 points:
1- The key mustn't be applied until the character is alphabetical, so (- means no encoding)
You are doing this:
String: w o r l d , s a y h e l l o !
Key: b a z b a z b a z b a z b ...
2
votes
vigenere cypher issues with embedding loops
You can nest loops by writing one within the other.
For example, the next piece of code prints the phrase "hello, world!" n x m times
// often known as an outer loop
for (int i = 0; i < n; i++)
{
...
2
votes
Why does my Vigenere solution give the wrong output only at certain positions in the string?
There are a few subtle problems here. I'm not going to give you the answer directly, but I can give you some hints.
Tip #1:
Look at the line of output from check50 relating to the error:
encrypts &...
2
votes
How to Check Whether a String Contains Non-Alphabetical Characters?
The string argv[] refers to string of strings. So when you are trying to do argv[1] then it means that you are looking for a string, but you cannot use isalpha(string), because the argument passed to ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
vigenere × 497pset2 × 397
cs50x × 38
check50 × 29
c × 22
vigenere.c × 19
segmentation-fault × 17
key × 12
pset2-vigenere × 11
modulo × 9
wraparound × 9
string × 8
cs50-vigenere × 7
keyword × 7
error × 6
help × 5
cs50-pset2 × 5
caesar × 4
python × 4
pointers × 4
fails-check50-but-works × 4
loop × 4
week2 × 4
output × 4
isalpha × 4