So I'm banging my head because my program doesn't print the spaces. For example, if the key is 1 and enter: a b c, it should output: b c d, but right now it's just printing "b" and doesn't recognize the space. I did also see this post: Pset 2 Caesar doesnt output spaces correctly and more :(
but still having issues. Any ideas?
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#define MAX_STRING 50
int main(int argc, char *argv[]) {
// User enters parameters for the argument
// Get the argument for argv[1], read in the key in that positon of the argument
char *key = argv[1];
// convert keyt to an integer
int key2 = atoi(key);
char cipherLetter[2] = ""; // sets all chars to '\0'
// Define variable for input
char text[MAX_STRING];
// Get user input
printf("\nplaintext: ");
scanf("%s", text);
// loop through each character in the word
for (int i = 0; i < strlen(text); i++) {
// check if character is an uppercase letter
if (isalpha(text[i]) && isupper(text[i])) {
// get the new ascii value w/ formula c = (plaintext + key) % 26, and add the char to an array
cipherLetter[0] = (text[i] + key2 - 65) % 26 + 65;
// print each character to screen
printf("%c", cipherLetter[0]);
}
// check if character is a lowercase letter
else if(isalpha(text[i]) && islower(text[i])) {
// get the new ascii value w/ formula c = (plaintext + key) % 26, and add the char to an array
cipherLetter[0] = (text[i] + key2 - 97) % 26 + 97;
// print each character to screen
printf("%c", cipherLetter[0]);
}
else {
// get the character
cipherLetter[0] = text[i];
// print each character to screen
printf("%c", cipherLetter[0]);
}
}
}