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 ...
user avatar
4 votes
Accepted

Pset2 Vigenere: Control reaches end of non-void function

Re: the for loop. A for loop structure has 3 sections: initialization, test, increment. Each section is separated by semicolons. Within each section, there can be multiple parts. Those parts are ...
user avatar
  • 64.2k
2 votes
Accepted

PSET 2; loop doesn't works like I want it to

You have nested loops. Don't. While you do have two indices (one in the text and one in the key), the index for the key is not independent. It starts at 0 as well and is incremented at encrypting a ...
user avatar
  • 20.7k
2 votes
Accepted

PSET2 Vigenere: Output bug, keyword loop going over strlen of key

There are a number of problems with this code. Let's deal with your question first. The code is constructed as a nested pair of loops. The outer for loop will loop over the length of the plain text ...
user avatar
  • 64.2k
1 vote
Accepted

Pset2 Vigenere some flaws in the code

Your issue is a misplaced ) when you calculate the key. int letterKey = tolower(k[j % kLen] - 'a'); You want to lowercase the key and then subtract 'a'. Move your closing brace.
user avatar
  • 18.4k
1 vote

PSET2 Vigenere: Output bug, keyword loop going over strlen of key

I would recommend you to do this problem set in one for loop. You can just loop through the plaintext. Using nested loops will make the problem more complicates than you think. It's because you only ...
user avatar
  • 55
1 vote
Accepted

Pset 2 - Vigenere Wraparound does not work properly

Very common error. The key index, k, is being incremented with EVERY plaintext char processed (incremented in the for loop setup). It should ONLY be incremented when an alpha is processed. Keep it ...
user avatar
  • 64.2k
1 vote
Accepted

PSET2 Vigenere: Control may reach end of non-void function error

You're right. The compiler just knows that there's a possibility of getting to the end of the code without seeing a return statement, so it's unhappy. However, your fix in the comments has a flaw. ...
user avatar
  • 64.2k
1 vote
Accepted

Vigenère spitting out random strings

There are a number of issues in the code that are impacting it. First, look at this: int *keyInt = malloc(strlen(key)); This allocates n bytes where n is the number of chars in the key string. ...
user avatar
  • 64.2k
1 vote
Accepted

Can someone check my vigenere code. I just don't get the idea of index

Since you declared int index = 0; inside the loop, it gets reset to 0 for each character, you always stay on the b of bacon. The fix would be to move that above your loop, outside the loop body.
user avatar
  • 20.7k
1 vote
Accepted

Pset2 Vigenere: Pointers/Function Question

* after a type is used to make a pointer. A pointer stores a memory address, and the pointer having that particular type will tell the compiler how to interpret the memory content when you dereference ...
user avatar
  • 20.7k
1 vote
Accepted

CS50 Vigenere - Failure: "rejects "Hax0r2" as keyword" - Should be very quick and easy

When checking for non-alphabetic characters, your loop should do exactly that, nothing more. After that loop, when you know no non-alphabetic character was in the keyword (as you would have returned ...
user avatar
  • 20.7k
1 vote
Accepted

Pset3 help : vigenere error

atoi takes a string as argument. You are passing it a single char. As an example, if you have atoi("123"); you'll get 123. But you can't pass it atoi('1') as that is a char. If you are trying to ...
user avatar
  • 18.4k
1 vote
Accepted

Pset 2 - vegenere

The good news is that you got the concept right. J needs to be reset at a certain point. The problem with that lies here: if (j >= strlen(k) - 1) Why - 1??? There is an additional problem ...
user avatar
  • 64.2k
1 vote
Accepted

Vigenere can't get correct output from key

I really don't know where your numbers start and end, and what they refer to (I don't think that's the output of the code you show), at least some whitespace between would have been nice. Also, the ...
user avatar
  • 20.7k
1 vote

Pset 2 - Vigenere Cipher Error: incompatible integer to pointer conversion, with a string/array element

The integer to pointer conversion does not happen at s[i] - 65 (which produces an int), but at return. You stated that your function returns a string, which is an alias for char*, a pointer to char. ...
user avatar
  • 20.7k

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