I am facing a small problem while solving caesar (PSET2).
I can make caesar but when I execute the program and provide a numerical command-line argument, I get back: Segmentation Fault, and the program just stops.
I would be extremely obliged if you could help me figure where the problem lies.
Any other feedback shall also be highly appreciated!
#include <stdio.h>
#include <cs50.h>
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, string k [])
{
if ( isalnum(k [1]) || argc == 2)
{
string s = get_string (" Message");
for (int i = 0, n = strlen(s); i < n; i++)
{
if (isalpha(s[i]))
{
int K = atoi ( k[1] );
int p = atoi ( s );
int c = (p + K) % 26;
int a = c + p;
printf ("%c", a + p);
return 0;
}
}
}
else
{
printf("Usage: ./caesar key \n");
return 1;
};
}