/** * caesar.c * * Andi Peng * Section, Week 3 * * Demonstrates how to debug a program using gdb */ #include #include #include #include #include int main(int argc, string argv[]) { int key = atoi(argv[1]); if (key < 0) { printf("You need to enter a positive integer key!\n"); return 1; } string plainText; do { plainText = GetString(); } while (plainText == NULL); for (int i = 0, n = strlen(plainText); i < n; i++) { if (isupper(plainText[i])) { plainText[i] = ((plainText[i] - 'A' + key) % 26) + 'A'; } else if (islower(plainText[i])) { plainText[i] = ((plainText[i] - 'a' + key) % 26) + 'a'; } } printf("%s\n", plainText); return 0; }