Skip to main content
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 ...
Cliff B's user avatar
  • 69k
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, ...
Cliff B's user avatar
  • 69k
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 <= ...
Llenk's user avatar
  • 744
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 ...
curiouskiwi's user avatar
  • 18.7k
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 ...
Cliff B's user avatar
  • 69k
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 ...
Cliff B's user avatar
  • 69k
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 ...
Cliff B's user avatar
  • 69k
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.
Vsjain's user avatar
  • 1,016
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
Cliff B's user avatar
  • 69k
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 ...
donyd's user avatar
  • 90
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 ...
Cliff B's user avatar
  • 69k
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.
Matías Gómez Seeber's user avatar
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 ...
Cliff B's user avatar
  • 69k
1 vote

Why So Many Check50 Errors on Caesar? Results match expected output

try for (j = 0; j < text_length; j++)
TokieSan's user avatar
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.
Blauelf's user avatar
  • 21k
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 ...
Cliff B's user avatar
  • 69k
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 ...
Cliff B's user avatar
  • 69k
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. ...
Blauelf's user avatar
  • 21k
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 ...
Cliff B's user avatar
  • 69k
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 ...
Blauelf's user avatar
  • 21k
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 ...
Cliff B's user avatar
  • 69k
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 ...
Llenk's user avatar
  • 744
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.
Vsjain's user avatar
  • 1,016
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 ...
Karthik G M's user avatar
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 ...
Cliff B's user avatar
  • 69k
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 (...
Cliff B's user avatar
  • 69k
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 ...
Ojou Nii's user avatar
  • 731
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 ...
harshdeeply's user avatar
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 ...
Cliff B's user avatar
  • 69k
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 ...
DinoCoderSaurus's user avatar

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