0

My code for substitution appears externally to be working correctly. It takes the key as an argument and prompts the user for the plaintext message. Both uppercase and lowercase keys work, and a mixture of both. The substitution happens correctly and respects upper and lowercase. It can handle very long messages fine.

However check50 is giving me the following errors:

Results for cs50/problems/2022/x/substitution generated by check50 v3.3.7
:) substitution.c exists
:) substitution.c compiles
:( encrypts "A" as "Z" using ZYXWVUTSRQPONMLKJIHGFEDCBA as key
    expected prompt for input, found none
:( encrypts "a" as "z" using ZYXWVUTSRQPONMLKJIHGFEDCBA as key
    expected prompt for input, found none
:( encrypts "ABC" as "NJQ" using NJQSUYBRXMOPFTHZVAWCGILKED as key
    expected prompt for input, found none
:( encrypts "XyZ" as "KeD" using NJQSUYBRXMOPFTHZVAWCGILKED as key
    expected prompt for input, found none
:( encrypts "This is CS50" as "Cbah ah KH50" using YUKFRNLBAVMWZTEOGXHCIPJSQD as key
    expected prompt for input, found none
:( encrypts "This is CS50" as "Cbah ah KH50" using yukfrnlbavmwzteogxhcipjsqd as key
    expected prompt for input, found none
:( encrypts "This is CS50" as "Cbah ah KH50" using YUKFRNLBAVMWZteogxhcipjsqd as key
    expected prompt for input, found none
:( encrypts all alphabetic characters using DWUSXNPQKEGCZFJBTLYROHIAVM as key
    expected prompt for input, found none
:( does not encrypt non-alphabetical characters using DWUSXNPQKEGCZFJBTLYROHIAVM as key
    expected prompt for input, found none
:) handles lack of key
:) handles too many arguments
:) handles invalid key length
:) handles invalid characters in key
:( handles duplicate characters in uppercase key
    failed to execute program due to segmentation fault
:( handles duplicate characters in lowercase key
    failed to execute program due to segmentation fault
:( handles multiple duplicate characters in key
    failed to execute program due to segmentation fault

No matter what I cannot replicate the issues manually, not even the segmentation faults. All of my tests give the intended result. Can someone help me figure out what I missed?

**admin edit to remove solution code **

edit: i just tried to compile in codespace instead of locally and see that it doesn't accept strdup(), even though string.h is linked at the top and the function is part of the CS50 manual. Could that be causing the issue?

1 Answer 1

0

Ok so the issue I think was that the solution was not possible to compile using CS50's Makefile. I was doing everything locally so I didn't notice there was an issue. Even though string.h is in the CS50 manual and you would assume that using the functions in it is as simple as including the header, you also have to include the following line at the top, before any other includes: #define _POSIX_C_SOURCE 200809L. Doing this fixed the issue and check50 returns all checks passed now.

2
  • The manual does mention the macro requirements for that function, but I can see that might not be obvious. We don't expect students to use strdup for this problem. (I don't think we ever use it in the course at all).
    – curiouskiwi
    Commented Dec 22, 2022 at 19:36
  • @curiouskiwi thanks! i checked again and it does. but i don't even know what a macro is since it's not been mentioned so far so i didn't think to look there. now that i've submitted it i will make sure to research and try to figure out what the 'intended' solution was. making duplicates of the key string seemed the most obvious to me but i ran into issues duplicating the string which is when i went looking and found this function.
    – 578574
    Commented Dec 23, 2022 at 14:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .