-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathweek2protocols1.cpp
More file actions
40 lines (35 loc) · 1.02 KB
/
week2protocols1.cpp
File metadata and controls
40 lines (35 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
const int BUFFER_SIZE = 26;
const int offset = 1;
#include <iostream>
static char inputString[] = "ydrsxdladccdclzqhmzqzrztbd"; //this test string should output zestyembeddedmarinarasauce
//puts a character into the output buffer
//remember that nothing will show until you print a newline.
void putc(char c){
printf("%c", c);
}
//returns a number for a corresponding letter
//a is 0, b is 1, all the way to z is 25
int letterToNumber(char c){
return c - 'a';
}
//returns a letter to the corresponding number
//a is 0, b is 1, all the way to z is 25
char numberToLetter(char i){
return i + 'a';
}
int main(){
//CODE GOES HERE
for (int i = 0; inputString[i] != '\0'; ++i) {
char c = inputString[i];
if (c >= 'a' && c <= 'z') {
int kkk = letterToNumber(c);
int shifted = (kkk + offset) % BUFFER_SIZE;
char out = numberToLetter(shifted);
putc(out);
}
else {
putc(c);
}
}
putc('\n');
}