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 ...
user avatar
  • 1,170
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 ...
user avatar
  • 18.3k
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 ...
user avatar
  • 63.1k
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 - ...
user avatar
  • 17.4k
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.
user avatar
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 ...
user avatar
  • 18.3k
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'...
user avatar
  • 2,146
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 ...
user avatar
  • 63.1k
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 ...
user avatar
  • 63.1k
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 ...
user avatar
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
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.
user avatar
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 ...
user avatar
  • 1,170
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 ...
user avatar
  • 3,316
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 ...
user avatar
  • 17.4k
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 ...
user avatar
  • 63.1k
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: ...
user avatar
  • 7,326
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 ...
user avatar
  • 63.1k
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 ...
user avatar
  • 63.1k
3 votes
Accepted

pset2 vigenere arguments

The correct way isif(argc !=2 || ! isalpha(key[j]))
user avatar
  • 5,172
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 ...
user avatar
  • 7,326
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 ...
user avatar
  • 63.1k
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 ...
user avatar
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 ...
user avatar
  • 63.1k
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 ...
user avatar
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 ...
user avatar
  • 63.1k
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 ...
user avatar
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++) { ...
user avatar
  • 17.4k
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 &...
user avatar
  • 2,625
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 ...
user avatar
  • 3,316

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