#include <cs50.h>
#include <stdio.h>
#include <stdlib.h> //covert str into int atoi()
#include <ctype.h> // isalpha(), isdigit() etc.
#include <string.h> //strlen() etc.
int main(int argc, string argv[])
{
// convert argv[1] into int
int key = atoi(argv[1]);
// if input is 2 command lines and argv > 0 and there is no alphabet n shit in argv[1] we good to go
if (argc == 2 && key > 0 && isdigit(argv[1]))
{
//ask for input to chiper
string plain = get_string("Plaintext: ");
int len_plain = strlen(plain);
// check each char in string plain
for (int i = 0; i < len_plain; i++)
{
// if its from 'a' to 'z' add number of key
if (plain[i] >= 'a' && plain[i] <= 'z')
{
char cipher = (plain[i] + key) % 26;
printf("%c", cipher);
return 0;
}
}
}
else
{
printf("Usage: ./caesar kay");
return 1;
}
}
При выполнении этого кода я столкнулся с ошибкой сегментации. Что я сделал не так? Я работал над этим кодом несколько дней, но не могу заставить его работать.