10
votes
How to handle the lack of argv[1] in caesar?
the issue is that you started your code
int main( int argc, string argv[])
{
int k = atoi(argv[1];
.
.
.
}
/// the mistakes is in the above assignment, if the there is no argv[1] so the OS will ...
7
votes
Accepted
pset6 - caesar - check50 error: "expected exit code 1, not 0"
main in Python no longer has a special meaning, but is a regular function, its name only chosen to conform to conventions based in C.
Try exit(1) instead of return 1.
Relevant python docs: https://...
4
votes
Accepted
pset2 caesar converting from ascii to alphabetical
Your formula is correct as well as the understanding of the formula, only that you are mixing two things in a wrong way, look carefully at the following expression:
((('s[i]' - 97) + n) % 26) + 97)
...
4
votes
Accepted
can't check until a frown turns upside down
To be clear, check50 is saying the program is not compiling and the later tests can't be executed until it does compile. The exit code 1 has nothing to do with your program's return statement. The ...
4
votes
Accepted
This should be right (Caesar)
The output does not match the spec. This plaintext : should be this plaintext:. The same with ciphertext:. There is no space between the word and the :. While this may seem "overly strict", it is good ...
4
votes
Accepted
Caesar code only works correctly when I add a random printf statement
It's a memory thing, as in you will get different results based on what is in memory.ctxt is declared as an array of chars. Here printf("ciphertext: %s\n", ctxt); is treating it like a string (viz ...
3
votes
pset2 (Hail, Caesar) - How to refine my code
One thing that sticks out about this is that you have special cases for spaces, commas, and exclamation marks. While I haven't tested your code directly, it looks like it wouldn't print characters ...
3
votes
Accepted
PSET 2 Caesar help
if (argc != 2)
{
return 1;
printf("try again\n");
}
else
{....
why else, it is an unnecessary statement, if (argc != 2), exit the program, but simply the next line of code is executed,
the ...
3
votes
Accepted
I just finished pset2 caesar. I get a segmentation fault if argc is other than 2
int k = atoi(argv[1]);
if (argc != 2)
{...........
You are assuming that argv [1] exists before checking that really exists, if we have more than two arguments your program will work well, but if you ...
3
votes
Accepted
Pset2 - caesar - segmentation fault
You actually have two problems with seg faults. First, the one that you probably haven't seen yet. The code tries to assign argv[1] to key before verifying it exists on the next line. If you run the ...
3
votes
why does this code not ask for a string?
It will. If you do not supply any command line arguments. Try it.
Why is that? Recall from Week 2 > Section > Command Line Arguments
argc will always be at least 1, the name of the program.
When ...
3
votes
Accepted
Pset 2 Caesar doesnt output spaces correctly and more :(
When you do not supply an argument, the runtime error comes here int k = atoi(argv[1]); because argv[1] is null and atoi cannot accept null. You need to check that the user has supplied an argument ...
3
votes
about caesar,i'm having a segmentation fault
Segmentation fault means that you are trying to access a section of memory that you don't have permission to use. This happens when you try to access an index of an array that doesn't exist.
Before ...
3
votes
What is the logical difference between if (isupper(text[i]) == true) and if (isupper(text[i]))?
The isupper() function (and all of it's cousins) returns an int, not a bool. Depending on which function call (isalpha, isfloat, isupper, islower, etc.) is invoked, an integer that is a power of 2 ...
3
votes
Accepted
make: Nothing to be done for `caesar'
This never has anything to do with the contents of the .c file and always to do with the location or name of the file.
It's a common error for new programmers. When you run the command make caesar, ...
3
votes
Accepted
check50 not approving my code but it looks like it's working
The good news is: it looks like your ciphering algorithm is working. Yay. The bad news is you missed a important detail in the spec.
Notice the difference between what cs50 is expecting: "ciphertext:...
3
votes
Accepted
Caesar Cipher doesn't Print Spaces
Looking at your code, I'm guessing that you aren't following the current course (2019 CS50x). You are missing many concepts that are required.
Saying that, your issue is that scanf as you've used it ...
3
votes
Accepted
Checking to see if the contents of a string is an integer
I do not remember now if such a check is necessary, anyway if you want to check if a character is integer we have the function isdigit (), you can search in google about it. I would separate the ...
3
votes
Accepted
I have "handles non-numeric key timed out while waiting for program to exit" problem inPset 2 and I can't solve it
Tip: If you open the link in the check50 results, it will show you the test data used and the result. In this case, it used 2x as the input parameter to caesar, and timed out.
When it times out, it ...
2
votes
atoi always returns 0
If this is for example for Caesar cipher and you're running ./caesar 2 then key should indeed be set to an integer of 2 as argv[0] is the program name and argv[1] is the string 2.
But int atoi(...
2
votes
caesar.c command line argument not stored in argv
The command line argument doesn't get passed to main via GetInt(). It gets passed via the command line.
You do something like
./caesar 13
And 13 is stored in argv[1]
Watch the walkthroughs and the ...
2
votes
Accepted
caesar--how do i make k an int? error "invalid operands to binary expression ('string' (aka 'char *' and 'int') in cipher section of code?
Hard to tell what you did without seeing the code, including the declaration for k and what you mean by "converted to an int". If you cast it as an int as in this, x = (int) k;, well, that only casts ...
2
votes
Accepted
pset2 caesar, argv[1]
It's always the problems that hide in plain sight that get us! ;-)
isdigit() is working exactly as expected. If a character is a digit, it returns a non-zero (not necessarily 1, try printing the ...
2
votes
Caesar cipher, i get the right output, but cs50 check won't accept it
in case you or somebody else out there is still wondering... as silly as it sounds, the lines
printf("plaintext: ");
and
printf("cyphertext: ");
are not as per pset specifications. Remove the ...
2
votes
Accepted
Pset6 2017 - 'str' object has no attribute 'isaplha' - caesar.py
Check your spelling! Sometimes it's the simple things ;)
2
votes
Accepted
Pset2 Caesar: extra letter printed at the end of ciphertext
Currently it looks like you're looping through your ciphertext from 0 up to strlen(plaintext), however, you assigned ciphertext the size of strlen(plaintext)+1.
Here's what's happening: The GetString(...
2
votes
Caesar (python) error
From the Hints section of the spec:
You might find chr and/or ord of help.
Python does not treat plaintext[i] the same way that C does. That's where ord comes in.
Python int is more like atoi ...
2
votes
Caesar (python) error
I think the problem is that you have a () around the if(plaintext[i].isalpha): when it should be if plaintext[i].isaplha(), and the same for isupper and islower. I had the same problem but when I ...
2
votes
Accepted
Question about Pset2 Caesar Code issue
It's not enough to apply the %26 to the cipher. You need to shift your character into range 0-25
plain[i] - 'A'
then add cipher
plain[i] - 'A' + cipher
then apply %26 to wrap numbers back to 0-25
...
2
votes
pset2 Caesar argc, argv, and string not being recognised when i 'make' the program
Simply put, you have three vars that aren't being used. argc and argv aren't being accessed at all in the code (you could remove them to eliminate two of the errors) and then you create string var ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
caesar × 427pset2 × 312
cs50x × 34
check50 × 34
pset2-caesar × 32
segmentation-fault × 20
caesar-cipher × 14
pset6 × 13
c × 13
python × 13
argv × 9
array × 8
command-line-arguments × 8
error × 7
isdigit × 7
pset × 6
cipher-pset2 × 6
argc × 6
atoi × 5
validatingthekey × 5
pset1 × 4
vigenere × 4
encryption × 4
ascii × 4
problemset2 × 4