Skip to main content
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 ...
DinoCoderSaurus's 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 ...
DinoCoderSaurus's user avatar
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 ...
ChrisG's user avatar
  • 7,396
3 votes
Accepted

pset2 vigenere arguments

The correct way isif(argc !=2 || ! isalpha(key[j]))
MARS's user avatar
  • 5,169
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 ...
Cliff B's user avatar
  • 69k
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 ...
Cliff B's user avatar
  • 69k
3 votes
Accepted

trail of strange characters after printing character array

Uhhuh. I see that it is doing a nice job of encoding and storing the encoded characters in an array. But have you also stored the end of string marker '\0' at the end of the string? printf will ...
Cliff B's user avatar
  • 69k
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 ...
robert_x44's 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 ...
Cliff B's user avatar
  • 69k
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 ...
Christopher Flores's 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 ...
Cliff B's user avatar
  • 69k
3 votes

I keep getting an error: incompatible pointer types passing 'string' (aka 'char *') to parameter of type 'string *' (aka 'char **')

This may sound mean, but the shift function is a mess. First, there's the error of the parameter mismatch. Note that declaring a string is really declaring a char *. Then, the parameter is itself an ...
Cliff B's user avatar
  • 69k
2 votes
Accepted

Why doesn't my vigenere work correctly for all inputs

Two classic errors. First, the index for the key is dependent the index for the plain text. They have to be independent of each other. The index for the plaintext will be incremented for every ...
Cliff B's user avatar
  • 69k
2 votes

How to Wrap Around Array Indexes?

If you want to wrap negatively as well (arrayIndex + arrayLength) % arrayLength + arrayLength ensures a positive result if your propgramming language supports Euclidean modulo.
David Chima's user avatar
2 votes

CS50 vigenere.c works for lower but not upper case letters

There are a couple of problems. The main one is that your code doesn't handle the case where the plain text and the key characters are not the same case. It assumes that if the plain text is lower ...
Cliff B's user avatar
  • 69k
2 votes
Accepted

Having trouble with CS50 Vigenere Problem - Don't really know what is wrong

There's a small mistake in the elseif statement under if condition - else if (isupper(s[i]) && islower(argv[1][j])) { printf("%c", ((((s[i] - 65) + (argv[1][j%kl] - 97)) % 26) ...
abhishek's user avatar
  • 152
2 votes
Accepted

why won't my code print the strlen[text] amount of characters?

In this code, i and j would only be in synch for the first pass. Try tracking what will happen with paper and pencil. Say that strlen(text) is 7 and strlen(key) is 3. In the first outer loop, i ...
Cliff B's user avatar
  • 69k
2 votes
Accepted

I have written this code for vigenere and it is giving 02 errors

The problem is that argv is an array of strings, and you try to use it as a single string. See this line: if (!isalpha (argv[1][i])) and this: if (isupper (argv[j])) Can you spot the difference?
ChrisG's user avatar
  • 7,396
2 votes
Accepted

vigenere.c unknown problem / am I an idiot?

It's not so much being an idiot as it is having tunnel vision. ;-) The problem isn't about vigKey. It's about what was done with the key string. If you look carefully at what the working code does, ...
Cliff B's user avatar
  • 69k
2 votes

Finished vigenere, but it fails to work as it should

There are a few problems with the code that need to be dealt with. Much of it involves starting counts and indexes at 1 when they should start at 0. First, the easy problem. The pset instructions ...
Cliff B's user avatar
  • 69k
2 votes
Accepted

Vigenere Code Duplication / Design Flaw

It's good that you're thinking about this. It says that you're looking for better, more efficient ways to write code. This scenario is actually a red flag that maybe there is a better way to do ...
Cliff B's user avatar
  • 69k
2 votes

Why doesn't this code work?

Because you are creating c as an array of strings. I think you meant to make c an array of n chars. Remember that a string is an array of chars in which the last char is a null terminator \0. I ...
Ricardo David Antonetti's user avatar
2 votes

vigenere.c key just wraps around ... if there is space in plain text it seems to ignore that key and move on to next

Please use argv[1] only after you've checked that argc is >=1, otherwise you might access an element that's after the array's end. Instead of isdigit, I'd use !isalpha. You could do that for example ...
Blauelf's user avatar
  • 21k
2 votes
Accepted

Pset2, Vigenere error "\ expected output, not a prompt for input" when I run check50

Your output does not match the spec. The spec says Implement a program that encrypts messages using Vigenère’s cipher, per the below. $ ./vigenere ABC plaintext: HELLO ciphertext: ...
DinoCoderSaurus's user avatar
2 votes
Accepted

What is the return value when isalpha() evaluates to true?

The problem is a lack of understanding of how many of these functions work. While you would think that isalpha() would return a bool, it doesn't. Instead, it returns a number. If it is false, it ...
Cliff B's user avatar
  • 69k
2 votes
Accepted

Help with Vignere pset2

I figured out my issue, the string checks were being double looped on second cycle, fixed the issue by adding constant variable shifts for the key string. #include <cs50.h> #include <stdio....
begginerbob's user avatar
2 votes
Accepted

null pointer passed as argument 1

You forgot to include the relevant code. You probably call your check function with a NULL pointer. This might happen for example if you use argv[1] before checking whether argc is greater than 1 (or ...
Blauelf's user avatar
  • 21k
2 votes
Accepted

C: Vigenere - incompatible pointer types passing 'char **' to parameter of type 'const char *

The error comes from here: for(int l=0; l<strlen(argv); l++) Think about it. strlen() wants a const char* or char*. You gave it argv, which is an array of the command line arguments. Because argv ...
SuperNovaCoder's user avatar
2 votes

Error with comparison between pointer and integer

What is ! = 2? Does not look like a valid expression to me. Use if (argc != 2). Instead of the other ! = 0, something like if (strlen(plaintext) != 0) would be correct, this condition would always ...
Blauelf's user avatar
  • 21k
2 votes
Accepted

Bugs in vigenere

This is a very common error. Simply put, the key index cannot be the same or based on the plain text index. The plain text index is incremented for every character, but the key index is ONLY ...
Cliff B's user avatar
  • 69k

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