Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- int main (void) {
- char *string = "Testing Here";
- int nums[] = {7, 0, 0};
- int num_elems = 3;
- int i = 0;
- while (*string) {
- int newchar = *string;
- int caps = -1;
- /* Normalize A..Z to 0..25 */
- if ('A' <= newchar && newchar <= 'Z') {
- caps = 1;
- newchar -= 'A';
- }
- /* Normalize a..z to 0..25 */
- else if ('a' <= newchar && newchar <= 'z') {
- caps = 0;
- newchar -= 'a';
- }
- /* All other characters print it out without changing */
- else
- printf("%c", *string);
- /* If we set caps to 0 or 1, then we need to process this letter */
- if (caps != -1) {
- newchar += nums[i];
- while (newchar < 0)
- newchar += 26;
- while (25 < newchar)
- newchar -= 26;
- /* Set the character back to the proper ASCII value */
- newchar = newchar + 65 + (caps == 0 ? 32 : 0);
- printf("%c", newchar);
- }
- i++;
- if (num_elems <= i) i = 0;
- string++;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement