3

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 cousins and you get a seg fault. The next issue is in the same line of code. ALWAYS check the value of argc FIRST. If argc is too small, it means that there aren't ...


2

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 argc. If it is NOT 2, the program should terminate immediately. Period. It shouldn't be built on an if/else structure and shouldn't encapsulate any other code. ...


1

The function atoi returns an integer. You're assigning it to a variable of type char *. Change it to int key to fix.


1

The problem is that k is out of scope at that point, meaning that it no longer exists. A variable is only "in scope" or in existence within the closest curly braces that surround it. Let me give you a visual. // other code precedes this. { int i = 4; // i is created and initialized. { int k = 0; // k is created and ...


1

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 inclusive. Add a key to it and it's even larger. Now, what happens when you apply %26 to it? You ALWAYS get a number between 0 and 25 inclusive. In other words, you ...


1

There are a lot of questions and problems here. Normally, it's one question to handle one or a few related problems. The messages like "handles lack of key" are describing the specific test being run. In this case, "Does the program handle the lack of a key, ie, a missing parameter when executing the program?" Another checks for ...


1

You can't reprompt a user for command line arguments. You will have to exit the program after printing the usage.


1

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

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 expects a certain parameter and/or path specified.


1

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 to find a seg fault?? Advice to new programmers


1

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 what's right to what's more efficient. And then, it gets even more interesting because you have to define what's more important, efficient programming, ...


1

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

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 and checks it, but not the chars that follow. You have to understand that isalpha() and all of its cousins only check one single char, not an entire string. If it ...


1

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 <= text_length; j++) In the loop statement here, you're going through j = text_length, but text[text_length] is the null terminating character. :( handles non-...


1

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 argc, meaning that it's trying to use an array element that might not even exist! That should solve some of your issues. Next, there's no code at all to ...


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