get started with the encoding program, start a new project and declare a character array that contains all 26 letters of the alphabet: 115.P2 4 char alpha[26] = {'A','B','C','D','E','F','G','H', etc. ','T','U','V','W','X','Y','Z'}; To display this to the screen, one option is to use a simple for loop as follows: for (n=0; n<26; n++) { printf("%c ", alpha[n]); } printf("\n"); Test this part of your
To get started with the encoding program, start a new project and declare a character array that
contains all 26 letters of the alphabet:
115.P2
4
char alpha[26] = {'A','B','C','D','E','F','G','H', etc. ','T','U','V','W','X','Y','Z'};
To display this to the screen, one option is to use a simple for loop as follows:
for (n=0; n<26; n++) {
printf("%c ", alpha[n]);
}
printf("\n");
Test this part of your program. You should then create a second array that will contain the
equivalent letters during encryption, and display both arrays to the screen. For an offset of 3
characters, the output of your program should be equivalent to the table on page 1 of these
notes. You should declare an integer to represent the key and use scanf_s as usual to obtain its
value from the user. The output of your program should look something like Figure 3.3 below.
The top array contains all the characters of the alphabet, and the bottom array contains the
encrypted version.
An important challenge here is that there are three characters (A, B and C) where their
encrypted versions are the last three letters of the alphabet (X, Y and Z). Think about how you
can generate the second array. One way of doing this is by moving the letters of the first array
by three to the right. This will in turn create three empty spaces at the start of the second array
which you must then fill. Your code should work for any key and not only for the example
considered in Figure 3.3.
No new programing concepts are required. You should be able to complete this part of the
exercise using the arrays and for loops from Laboratory 1 – although partly an exercise in C
programing it is also an exercise in logical thinking!
Build your program step by step and test it as you go. If you run into problems compiling your
program, you may find it useful to return to an earlier version and then to add one new line or
segment of code at a time, to determine if this is the problem. For example, it makes good
sense to first write a program to simply generate and display the 26 letter alphabet (as already
suggested above).
Step by step
Solved in 2 steps