CS120
Programming Assignment #10
Due Wednesday May 2nd.
One advantage of C-style strings is that because they are stored
as arrays it's easy to manipulate them one character at a time.
The most common approach is to use a while loop that steps through each element of the
array until the null character '\0' is reached:
while(str[i] != '\0'){
   // do something to str[i] to change the character
   i++;
}
Because characters are represented by their ASCII value
(American Standard Code for Information Interchange)
you can manipulate the characters using arithmatic. For example, a simple way to encrypt a string is to
add (or subtract) a fixed amount from each character (str[i] = str[i] + 1).
For this assignment do the following:
- Use the scanf function to read a string of characters (without spaces) from the user.
- Use printf to print the string.
- Use a loop to "encrypt" the string by changing the character values.
- If you're encrypting the sting by addition the characters high in the alphabet, z, y, etc. may become symbols
that aren't characters. For example 'z'+2 = '|' (see the ASCII table linked above). Use an if statement or a modulus operator to
'loop' these characters back to the beginning of the alphabet. E.g. 'z'+2 = 'b'. Alternatively if your encrypting via subtraction the problem is with letter at the beginning of the alphabet a, b, c, etc. again use an if statment to catch
letters that are encrypted to non-letters and loop them to the end of the alphabet: 'a' - 2 = 'y'.
- Another problem is with non-characters. For this project don't encrypt them at all, e.g. a ',' remains a ','. To make
this easier there are functions for identifying characters and non-characters in the
ctype library. Use the isupper() and islower() functions to identify and only 'encrypt' characters.
- Finally have the program use printf() to print the encrypted string.
Turn in: A copy of the code and sample output showing how the encryption works.