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
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
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 ...
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 ...
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 ...
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?
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 ...
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.
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) ...
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, ...
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 ...
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 ...
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 ...
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 ...
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: ...
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 ...
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....
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 ...
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 ...
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 ...
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 ...
2
votes
Accepted
My vigenere gets plaintext and doesn't print any ciphertext
Do not read argv[1] before you have checked argc. If argc<2, argv[1] does not even exist, it's outside of the argv array.
if (!isalpha(argv[1]))
won't work. isalpha takes a char, while key/argv[1]...
2
votes
Pset2 - Vigenere looping problem
Your for loop syntax is not likely doing what you think it is.
for (int g = 0, k = 0, z = strlen (plaintext), v = strlen (key); g < v, k < z; g++, k++)
Comma operators are sometimes used in ...
2
votes
can someone help me with this problem, im getting vignere.c:58:59: runtime error: division by zero
Suppose the first letter of your key is 'a'. After your for loop is done, the value stored in key[0] is no longer 97 ('a'), but 0.
When you then, later, do strlen(key), the value returned is 0, ...
2
votes
Accepted
why am i getting "can't check until a frown turns upside down"?
It's simple. Since the program didn't compile, none of the tests that follow can be done. Were you able to compile the vigenere program locally? Maybe you made a change to vigenere.c that introduced ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
vigenere × 495pset2 × 395
cs50x × 38
check50 × 29
c × 23
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