I'm trying to solve the Caesar pset, and I think I'm mostly on the right way, but I just started getting the error "Segmentation fault (core dumped)". I've attached the code, hopefully someone can point out, what I did wrong.
#include <cs50.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
char rotate(char c, int n);
int main(int argc, string argv[])
{
// SAVE CLA AS VARIABLES
string plaintext = get_string("plaintext: ");
int key = atoi(argv[1]);
string ciphertext = "";
int length = strlen(plaintext);
for (int i = 0; i < length; i++)
{
ciphertext[i] = rotate(plaintext[i], key);
}
printf("%s\n", ciphertext);
}
char rotate(char c, int n)
{
//test if c = key is in right range
c = c + n;
while (c > 122)
{
c = c - 122 + 64;
}
return c;
}