Really having a hard time doing this caesar problem my cipher text is not taking spaces to account and when I type in ./caesar by itself it gives me a message like this:
caesar.c:10:18: runtime error: null pointer passed as argument 1, which is declared to never be null /usr/include/stdlib.h:148:33: note: nonnull attribute specified here Segmentation fault
I don't know what else I'm doing wrong is it possibly my first if else loop?
#include <stdio.h>
#include <cs50.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
int main(int argc, string argv[])
{
// establish conditions for key which is k also get unencrypted string
int k = atoi(argv[1]);
if(argc==2 && k)
{
string s = get_string();
printf("plaintext:%s\n", s);
//check each individual character of plaintext and preserve characters
printf("Ciphertext:");
for(int i = 0, n = strlen(s); i < n; i++)
{
if(isalpha(s[i]), isupper(s[i]))
{
// convert asci to alphbetical for upper case
int cipher = s[i]-65;
int c = (cipher + k) % 26;
printf("%c", c+65);
}
//convert for lower case
else if(islower (s[i]), isalpha(s[i]))
{
int cipher2 = s[i]-97;
int d = (cipher2 + k) % 26;
printf("%c", d+97);
}
}
printf("\n");
return 0;
}
else
{
printf("Usage: ./caesar k\n");
return 1;
}
}