BUPT-homework/semester1/pset4/2-ROT3.c

24 lines
377 B
C
Raw Normal View History

2021-10-19 22:58:02 +08:00
#include <stdio.h>
// Declare prototypes
int process(char c);
int main(void) {
int temp;
while ((temp = getc(stdin)) != '\n') {
printf("%c", process(temp));
}
printf("\n");
return 0;
}
int process(char c) {
if (c >= 'a' && c <= 'z') { // If c is a - z
return (c - 'a' + 3) % 26 + 'a';
}
else
return (c - 'A' + 3) % 26 + 'A'; // Else if c is A - Z
}