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 ...
user avatar
  • 63.2k
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 <= ...
user avatar
  • 699
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 ...
user avatar
  • 18.3k
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 ...
user avatar
  • 63.2k
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.
user avatar
  • 20.7k
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 ...
user avatar
  • 63.2k
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 ...
user avatar
  • 63.2k
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. ...
user avatar
  • 20.7k
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 ...
user avatar
  • 63.2k
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 ...
user avatar
  • 20.7k
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.
user avatar
  • 957
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
user avatar
  • 63.2k
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 ...
user avatar
  • 90
1 vote

:( 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 ...
user avatar
  • 63.2k
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 ...
user avatar
  • 63.2k
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.
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 ...
user avatar
  • 63.2k
1 vote

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

try for (j = 0; j < text_length; j++)
user avatar
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 ...
user avatar
  • 63.2k
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 ...
user avatar
  • 699
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.
user avatar
  • 957
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 ...
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 ...
user avatar
  • 63.2k
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 (...
user avatar
  • 63.2k
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 ...
user avatar
  • 701
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 ...
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 ...
user avatar
  • 63.2k
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 ...
user avatar
1 vote

PSET 2 Caesar - Errors when key is a large number

cipher_digits is of type char, more precisely 8-bit signed char, meaning it can store values from -128 to 127. What will happen if the sum is greater than 127? It will wrap around, interpreting the ...
user avatar
  • 20.7k
1 vote

implicit declaration of function 'crypt' is invalid in C99

Look carefully at the following two statements: void cyrpt(string s, int k); ..... crypt(s,k);
user avatar
  • 5,172

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