Ok so i have the basic idea of caesar and heres what i have so far:
#include <stdio.h>
#include <cs50.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <ctype.h>
int main(int argc, string argv[]){
int k = atoi(argv[1]);
string toEncrypt;
if(argc != 2 || k < 0){
printf("k cant be negative and you must enter a command line integer");
return 1;
}
printf("Please enter a message to encrypt with your command line integer: ");
toEncrypt = GetString();
for (int i = 0, n = strlen(toEncrypt); i < n; i++){
if(isalpha(toEncrypt[i])){
int ascii = (int)toEncrypt[i];
char encrypted = (char)ascii + k;
printf("%c", encrypted);
}
}
printf("\n");
}
But the problem is that for anything that isn't a letter, it just skips it and doesn't print it at all..
I know how to make the letters wrap around after 26 but first i need to get this right. Does anyone have any idea how I can print the non-letter characters or symbols in their right places without changing them?