So I'm on week 2 of the harvard cs50 online course (2021x version). We're supposed to write a program that encrypts a text, moving every letters ASCII code by a certain amount, decided by the user through the command line. Here is the full problem. I'm nearly done, but already when I try to run the program, (it compiles just fine), it tells me there is a segmentation error. I don't really understand the problem. I've read that the problem has to do with accessing a certain part of memory that isn't accessible?? How do I solve this problem? Thank you in advance! Here is my code..
#include <stdio.h>
#include <cs50.h>
#include <ctype.h>
#include <string.h>
int main(int argc, string argv[])
{
int k, i;
if (argc == 2 && isdigit(argv[1]) && argv[1] > 0)
{
k = (int) argv[1];
string plaintext = get_string("plaintext: ");
printf("cyphertext: ");
for (i = 0; i < strlen(plaintext); i++)
{
if (islower(plaintext[i]) || isupper(plaintext[i]))
{
printf("%c", (((plaintext[i] + k) - 97) % 26) + 97);
return 0;
}
}
}
else
{
printf("Usage: ./caesar key");
return 1;
}
}