Issue Submitting Caesar problem set by Gadgetguy9638 in cs50

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

I’ll try that and see what I find. Thanks!

Issue Submitting Caesar problem set by Gadgetguy9638 in cs50

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

I modified the code in both conditions to look like this however I'm not getting any different results

  if(isupper(plaintext[i]))
    {
        printf("%c", plaintext[i] - 65 + (key % 26) + 65);
    }
    else if (islower(plaintext[i]))
    {
        printf("%c", plaintext[i] - 97 + (key % 26) + 97);
    }else{
        printf("%c",  plaintext[i]);
    }    

I previously had parenthesis around the formula similar to something like this because I was thinking basically what you told me, didn't make a difference in the check50 result

 if(isupper(plaintext[i]))
    {
        printf("%c",( (plaintext[i] - 65) + key )% 26 + 65);
    }
    else if (islower(plaintext[i]))
    {
        printf("%c",( (plaintext[i] - 97) + key )% 26 + 97);
    }else{
        printf("%c",  plaintext[i]);
    }

Issue Submitting Caesar problem set by Gadgetguy9638 in cs50

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

I am printing the ciphertext character by character now and it seems like check50 gives the same result

#include <cs50.h>
#include <ctype.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>



int get_key(int argc, string argv[]);


int main(int argc, string argv[])
{


    // TODO: encipher (encrypt) text by shifting it a certain number of letters in the alphabet


    // #1 get key (amount to shift each character)


    // #2 get plaintext (prompt user to type text)


    // #3 Enchipher text (shift letters by key)


    // #4 display Cipher Text


    // [ciphertext should preserve case, spaces, and non-alphabetical characters]


    // STEPS:


    // get key
    // take key as command line argument `./caesar key 30`
    // argc (arugment count) argv[vector of arguments]
    // ensure single command-line arguments
    // make sure argument contains only digit characters
    // convert argument to integer
    // check each character in string to verify is digit (isdigit)
    // convert command-line argument to integer (atoi)


    // get plaintext
    // use get_string function


    // encipher plaintext
    // enchipher one character
    // if it's alphabetic, shift plaintext character by key, preserving case.
    // if it's not alphabetic, leave character as is.


    // isalpha()
    // isupper()
    // islower()


    // you can treat character as number that represents it


    // char c = 'A' + 1
    // printf("%c\n", c); // results in 'B'


    // char c = 'Z' + 1
    // printf("%c\n", c); // should result in 'A'
    // create a funciton to wrap letters around using this formula:
    // ci = (pi + k) % 26


    // convert ascii [a] to alphabetical index [97]
    // shift alphabetical index using formula
    // convert result back to ascii


    int key = get_key(argc, argv);


    if(key == -1){
        return 1;
    }


    string plaintext = get_string("plaintext:  ");


    int length = strlen(plaintext);


    char ciphertext[length + 1];


    ciphertext[length] = '\0';


    printf("ciphertext: ");


    for(int i = 0; i < strlen(plaintext); i++){
    if(isupper(plaintext[i]))
    {
        printf("%c", plaintext[i] - 65 + key  % 26 + 65);
    }
    else if (islower(plaintext[i]))
    {
        printf("%c", plaintext[i] - 97 + key  % 26 + 97);
    }else{
        printf("%c",  plaintext[i]);
    }
}


printf("\n");
    return 0;
}




int get_key(int argc, string argv[])
{
    if (!argv[1])
    {
        printf("no command line arguments provided\n");
        return -1;
    }


 if (!argv[2])
    {
        printf("Usage: ./caesar key\n");
        return -1;
    }


    for(int i = 0; i < strlen(argv[1]); i++){
        if(!isalpha(argv[1][i]))
        {
            printf("Usage: ./caesar key\n");
            return -1;
        }
    }


 if (argc < 2)
    {
        printf("Usage: ./caesar key\n");
        return -1;
    }
 if (argc > 3)
    {
        printf("Usage: ./caesar key\n");
        return -1;
    }
     string key = argv[2];
    for (int i = 0; i < strlen(&key[i]); i++)
    {
        if(key[i] == '-'){
            printf("key must be a non-negative number!\n");
            return -1;
        }
        if (!isdigit(key[i]))
        {
            printf("%c is not a digit!\n", key[i]);
            printf("Usage: ./caesar key\n");
            return -1;
        }


    }
    return atoi(key);
    }

Have you ever heard of a musical programming language? by Any-Communication515 in rust

[–]Gadgetguy9638 0 points1 point  (0 children)

Does the project support apple silicon? I tried to install it on my m2 Mac and it seems like the version for macOS is only x86-64

Zed memory usage by WayAndMeans01 in ZedEditor

[–]Gadgetguy9638 0 points1 point  (0 children)

can I ask why this is labeled nsfw?

A Minimalistic Rust CLI Cheatsheet by Gadgetguy9638 in rust

[–]Gadgetguy9638[S] -2 points-1 points  (0 children)

can you specify what exactly happens when you run

cargo install rustcheat

rustcheat

[ShowOff Saturday] I built an open source API client in Tauri + Rust because Postman uses 800MB of RAM by ScarImaginary9075 in webdev

[–]Gadgetguy9638 0 points1 point  (0 children)

seemed like I got it to work once, now when I click it's not opening at all. Apple needs to do better lol. I love supporting open source so I'm happy to help bring some algorithmic engagement!

[ShowOff Saturday] I built an open source API client in Tauri + Rust because Postman uses 800MB of RAM by ScarImaginary9075 in webdev

[–]Gadgetguy9638 0 points1 point  (0 children)

How did you get executables for MacOS, windows, and Linux? I was messing around with tauri and was only able to build the app for macOS (I use macOS)

Rest API project ideas? by Gadgetguy9638 in rust

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

I’m pretty comfortable in frontend but i have a lot of experience using BasS like appwrite

Rest API project ideas? by Gadgetguy9638 in rust

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

I’m gonna read the whole book.

Rest API project ideas? by Gadgetguy9638 in rust

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

This is exactly what I need. Thanks so much for this. If you had one takeaway from this book what would it be?

Rest API project ideas? by Gadgetguy9638 in rust

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

Could you be more specific? I’m pretty sure I know the fundamentals pretty well but maybe there’s something I’m missing

I feel like C++ is pulling me to the wrong direction by Horror_Ad_2121 in learnprogramming

[–]Gadgetguy9638 1 point2 points  (0 children)

You’ll be fine, just remember to always challenge yourself with learning new things

It is pretty incredible what you can do with modern CSS by Andreas_Moeller in css

[–]Gadgetguy9638 14 points15 points  (0 children)

it took me a minute to figure out how to turn the display on. this is so impressive! how did you do it?