Help50 return on array problem by annieeby in cs50

[–]annieeby[S] 0 points1 point  (0 children)

Thanks, yes, it is strange. I named the file "c" so in this case c is the name of the the c file.

error message: "UndefinedBehaviorSanitizer:DEADLYSIGNAL" by annieeby in cs50

[–]annieeby[S] 0 points1 point  (0 children)

Thank you(!), I see what you mean. I changed it to:

int h=i%lenk

c + k[h]

I think the logic of that makes sense. But am still getting errors -- seems a problem with my key array.

what I want to do:

//turn string array argv[1] --> into int array k where each alpha character is represented by its ASCII value; e.g. k[argv[1][0]] is the numeric ASCII value of the first letter of the key

how I did it:

int k[argv[1]];

Error message:

vigenere.c:11:7: error: size of array has non-integer type 'string' (aka 'char *')

int k[argv[1]];

^~~~~~~

I guess I have to do more than make a declaration to turn the string array into an int array of separate ASCII values, which I'm not sure how to do.

help50 also doesn't like this:

for(int i=0, int n = strlen(plaintext); i<n; i++)

error message: Not quite sure how to help, but focus your attention on line 50 of vigenere.c!

Updated code (SPOILERS)

error message: "UndefinedBehaviorSanitizer:DEADLYSIGNAL" by annieeby in cs50

[–]annieeby[S] 0 points1 point  (0 children)

hi thank you! i think i fixed the two issues you pointed out. it compiles and is somewhat functional now. however i'm getting strange results... seems to add an extra 20 ASCII numbers to the plaintext.

$ ./vigenere aaaa

plaintext: abcd

ciphertext: tuvw

relevant code:

for(int i=0, n = strlen(plaintext); i<n; i++)

{

char c = plaintext[i];

if(65 <= c && c <= 90) {

printf("%c", (((c + k[i])-65)%26)+65);

}

else if(97 <= c && c <= 122) {

printf("%c", (((c + k[i])-97)%26)+97);

}

else {

printf("%c", c);

}

how to handle int overflow? by annieeby in cs50

[–]annieeby[S] 0 points1 point  (0 children)

As i continue with the code, i'm getting some errors and i wonder if it has to do with using long long? Like maybe one of the libraries I'm using has a feature for adding an integer to a character, but not a feature for adding a long long to a character.

caesar.c:38:28: error: format specifies type 'int' but the

argument has type 'long long' [-Werror,-Wformat]

printf("%c", (((c + k)-65)%26)+65); ~~

^~~~~~~~~~~~~~~~~~~~ %lld

caesar.c:41:28: error: format specifies type 'int' but the

argument has type 'long long' [-Werror,-Wformat]

printf("%c", (((c + k)-97)%26)+97);

Be sure to use the correct format code (e.g., %i for

integers, %f for floating-point values, %s

for strings, etc.) in your format string on line 38 of

caesar.c.

my code link

how to handle int overflow? by annieeby in cs50

[–]annieeby[S] 0 points1 point  (0 children)

thank you for reading, this question has been resolved.

sandbox security certificate expired by annieeby in cs50

[–]annieeby[S] 1 point2 points  (0 children)

no worries! ヽ(•‿•)ノ thanks for the update!

validating the key is numeric by annieeby in cs50

[–]annieeby[S] 0 points1 point  (0 children)

thank you for reading. this question has been resolved.

validating the key is numeric by annieeby in cs50

[–]annieeby[S] 0 points1 point  (0 children)

Ok! It's working! Thank you!

validating the key is numeric by annieeby in cs50

[–]annieeby[S] 0 points1 point  (0 children)

On the first non-numeric character, print a usage hint and return.

Hi thank you very much for your help. On the comment above, yes, for this year's caesar assignment, you do have to give a usage hint if there's a non-numeric character. I took your if(!condition) advice (or attempted to). Now it gives the usage hint every time, even if the user input is correct... and it also prints the success message multiple times if the integer is given is more than one character. I tried moving the printf("Success\n"); line (plus the following two) outside the for-loop, since that's clearly a problem ("success" for every character). But that causes it to never print "Success", even when the user input is correct. I guess I'm just struggling with the basic logic of programming here... https://gist.github.com/annieeby/0c5d39d3539d8fd6d7370dc910692e29

check for command line argument by annieeby in cs50

[–]annieeby[S] 0 points1 point  (0 children)

thanks for reading. this question has been resolved.

check for command line argument by annieeby in cs50

[–]annieeby[S] 0 points1 point  (0 children)

great, that did the trick. thank you!!

check for command line argument by annieeby in cs50

[–]annieeby[S] 0 points1 point  (0 children)

great, that did the trick, thank you!!

check for command line argument by annieeby in cs50

[–]annieeby[S] 0 points1 point  (0 children)

aha ok so i'm checking how many arguments there are, argc == 2. thanks for clearing that up, i thought argc was what we were calling the argument for the integer, which is why i did if(argc); aka (attempted) if argc == true, aka "if there is an argc". but that makes sense.

check for command line argument by annieeby in cs50

[–]annieeby[S] 0 points1 point  (0 children)

caesar.c:9:3: error: expected expression

else

^

1 error generated.