3
votes
Accepted
Segmentation Fault while running caesar
The immediate problem lies here:
if ( isalnum(k [1]) || argc == 2)
The isalnum() function requires a single char to be passed to it. k[1] is a string. Pass a string to isalnum or any of it's ...
3
votes
Accepted
pset 2 Segmentation fault (core dumped)
Look at this line of code:
if (isdigit(s))
The isdigit() function takes a single character as input, but s is a string. This triggers a seg fault.
The code needs to process each char in the string, ...
2
votes
Accepted
Why So Many Check50 Errors on Caesar? Results match expected output
You can't see it in your output, but you're actually printing one character beyond the end of the string, which is the null terminating character.
printf("ciphertext: ");
for (j = 0; j <= ...
2
votes
Accepted
Problems with check50 for pset2 caesar 2019
To answer your first question, check50 is not available in the Lab. (check50 is not introduced until Week 3 when you will move to the IDE).
edit
To answer your second question, you are only seeing a ...
2
votes
:( handles lack of key or argv[1] failed to execute program due to segmentation fault
Does the code check to see that there is exactly one input parameter string BEFORE trying to do anything with argv[1]? Doesn't look like it.
Also, you might benefit from reading this:
Do YOU know how ...
2
votes
Accepted
Errors in Caesar pset2 and Wrong Output
You're getting a seg fault because the code tries to work with argv[1] before checking whether it exists. "Ready, Fire, Aim!"
The very first thing that must be done is to check the value of ...
2
votes
Accepted
I'm stuck at PSet 2 Caesar Cipher: The alphabets don't follow my modulo 26. It goes beyond it, printing non-alphabetic characters
The problem lies here:
int asciiValue = plaintext[i]+key%26;
Simply put, it won't work at all. plaintext[i] contains an ASCII value for a letter. That's a number somewhere between 65 and 122 ...
1
vote
Caesar pset2 How to Reprompt user for Command Line Argument?
You can't reprompt a user for command line arguments. You will have to exit the program after printing the usage.
1
vote
Caesar pset2 How to Reprompt user for Command Line Argument?
Perhaps a review of the class material on command line arguments is in order?
https://cs50.harvard.edu/x/2020/notes/2/#command-line-arguments
1
vote
Accepted
cs50 problemset 2 caeser check50 command gives me this error : 'You seem to be missing these required files: caesar.c'
Your spelling of caesar is wrong - you have it as caeser.
You need to change both the file name and the folder name to "caes[a]r"
The command you are using is most like an api endpoint and ...
1
vote
Accepted
Question on Pset2 Caeser
One of the things you'll learn in programming is that there are usually many "right" ways to do things. Later, you'll also see a lesson on programming efficiency. The question shifts from ...
1
vote
Question on Pset2 Caeser
The video on the assignment gave hints towards using that approach. I can't tell you it's "right" or "the best", but it makes perfect sense.
1
vote
validating command line argument
The code runs because it isn't validating that all of the chars in argv[1] are digits. The test in the code, isalpha(*argv[1]) actually takes the address of argv[1] as the location of a single char ...
1
vote
Why So Many Check50 Errors on Caesar? Results match expected output
try
for (j = 0; j < text_length; j++)
1
vote
Accepted
Pset 2 Caesar: "invalid operands to binary expression ('string' (aka 'char *') and 'int')"
In that formula, use p[i], the ith character of p, not p itself.
1
vote
Accepted
Pset2 Caesar - Fails on "barfoo" only
When the key is sufficiently large enough, the algorithm that was designed here won't work. Imagine if the key were 1000. The results generated will not even be a valid ASCII code. A key of 65 is ...
1
vote
Accepted
PSET2 Caesar Segmentation Fault
I didn't test all of your code, but you're close. Look a few lines later. This will definitely cause a seg fault:
if (isalpha(p))
The isalpha() function takes a single char. p is a string. This ...
1
vote
Pset 2( 2 Questions) Caesar
Quoting the problem specification:
You can assume that, if a user does provide a command-line argument, it will be a non-negative integer (e.g., 1). No need to check that it’s indeed numeric.
...
1
vote
Accepted
CS50 PSET 2 CAESAR
The main problem lies in your if/if/else structure. The first if statement will execute, independently of what follows. Then, the second if statement will be executed. If it's true, then the else ...
1
vote
Accepted
pset2//caesar- relational operator result unused error
First to the error: i<len,k>=0 uses the comma operator, which evaluates its left side, discards the result, and evaluates to its right side. So i<len,k>=0 is the same as k>=0, the value ...
1
vote
Accepted
Caesar Pset2 Handles non-numeric key :(
First of all, the code MUST check for lack of a key, i.e., a valid number of parameters by checking the value of argc FIRST!!! Right now, the code is trying to use argv[1] before checking the value of ...
1
vote
Accepted
Getting a segmentation fault when testing my code. I want to make sure the user is typing a correct input e.g. ./caesar 2 and not ./ caesar a
if (isalpha (key))
In this line, isalpha is written to take an int, but key is a string. There's no automatic conversion from string to int, the way there is from char to int. I think you intend to ...
1
vote
Pset2 Caesar Memory Leak
Try using '\0' in place of (char) 0 for null terminating character of cipher.
If this helps, click the tick mark.
1
vote
Caesar problem: Validating keys
They are right, your program is only checking the first character of argv[1].
Try to think - your for loop checks the first character; if its not a digit, it throws an error and ends the program. Or ...
1
vote
Accepted
Pset 2 caesar handles non-numeric key fail
Didn't the spec say that the code should test for non-numeric keys and should print an error message when a non-numeric is found?
Perhaps you need to validate the key as all numeric, and then use ...
1
vote
Accepted
I'm getting an for error expected expression. What exactly I'm I doing wrong?
First of all, this is why it's important to get the indentation aligned correctly so you can see what goes with what. Here's the corrected indentation.
int main(int argc, string argv[])
{
if (...
1
vote
Accepted
I have the error of :( handles non numeric key - timed out while waiting for program to exit in Problem Set 2 Caesar
It's pretty simple it means your program is handling non-numeric key. Try dis with your program ./caesar abaed You're program doesn't treat this as an error because the keys are supposed to be only ...
1
vote
Why doesn't my Caesar code not return an output for the cipher text?
In your code where the plaintext gets converted to ciphertext, each of the characters in the plaintext string is trying to add an integer value to a character type and then divides the sum by 26 to ...
1
vote
Accepted
Why does my code keep returning 1 with the error message even though I input a digit?
Let's look at what's really happening:
char n = argv[1][i];
int digit = isdigit(n);
if (n != digit)
You have to thoroughly understand every step here. First, the code will copy the ...
1
vote
Pset2 - Ceasar - Non Void function error
The ceasar function (defined here: int ceasar (char Plaintext[], int key) does not have any return statement. Since this is a function "with side effects", ie it is printing the ouptut, then it could ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
pset2-caesar × 78pset2 × 38
caesar × 32
cs50x × 10
check50 × 8
segmentation-fault × 6
cipher-pset2 × 6
caesar-cipher × 6
c × 5
cs50-ide × 3
pset × 2
fails-check50-but-works × 2
cs50x2019 × 2
cs50-pset2 × 2
check × 1
function × 1
compilation-error × 1
pset2-crack × 1
week2 × 1
printf × 1
modulo × 1
arrays × 1
invalid × 1
bash × 1
caeser × 1