So, here’s Caesar. This was annoying actually. Firstly, need to think about ASCII, characters and integer equivalents which I don’t really want to think about. That’s the thing with learning to code, or perhaps learning anything really. Unfortunately, it seems you have to practice and to practice, you have to do sample problems that give you that practice. Issue is, that may involve certain problems that are not interesting to have to solve, but you need to :(.
Secondly, I didn’t scroll down and read some hints in the problem statement that would have helped me solve it much quicker. Dumb! There’s maybe a .h include here I don’t need anymore but not spending time to double check. Also, bugging the hell out of me is C language. Basic stuff like checking if an argument is digit requires a bloody for loop to be implemented. Seriously! Where are the library functions! Can’t wait to move to Python. The problem statement suggested using functions to abstract certain logic of the code. Would likely be better but can’t be bothered doing that now as spent far too long on this. This is just part.
#include <cs50.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
int main(int argc, string argv[])
{
if (argc < 2 || argc > 2)
{
printf("Usage: ./caesar key\n");
return 1;
}
for (int j = 0; j < strlen(argv[1]); j++)
{
if ()
{
printf("Usage: ./caesar key\n");
return 1;
}
}
/* printf("Passed first tests with: %s\n", argv[1]); */
/* printf("plaintext: %s", argv[1]); */
string source_text = get_string("plaintext: ");
printf("ciphertext: ");
int key = atoi(argv[1]);
for (int i = 0; i < strlen(source_text); i++)
{
if (isalpha(source_text[i]) == 0)
{
printf("%c", source_text[i]);
}
else
{
if islower(source_text[i])
{
}
else if isupper(source_text[i])
{
}
}
}
printf("\n");
}