The immediate problem lies here:
if ( isalnum(k ) || argc == 2)
The isalnum() function requires a single char to be passed to it. k 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 ...
You're getting a seg fault because the code tries to work with argv 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. ...
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 ...
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 ...
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 ...
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.
Does the code check to see that there is exactly one input parameter string BEFORE trying to do anything with argv? 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
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, ...
The code runs because it isn't validating that all of the chars in argv are digits. The test in the code, isalpha(*argv) actually takes the address of argv 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 ...
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.
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-...
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 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 ...