Advertisement
Guest User

Untitled

a guest
Aug 22nd, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int main (void) {
  5. char *string = "Testing Here";
  6. int nums[] = {7, 0, 0};
  7. int num_elems = 3;
  8. int i = 0;
  9. while (*string) {
  10. int newchar = *string;
  11. int caps = -1;
  12. /* Normalize A..Z to 0..25 */
  13. if ('A' <= newchar && newchar <= 'Z') {
  14. caps = 1;
  15. newchar -= 'A';
  16. }
  17. /* Normalize a..z to 0..25 */
  18. else if ('a' <= newchar && newchar <= 'z') {
  19. caps = 0;
  20. newchar -= 'a';
  21. }
  22. /* All other characters print it out without changing */
  23. else
  24. printf("%c", *string);
  25. /* If we set caps to 0 or 1, then we need to process this letter */
  26. if (caps != -1) {
  27. newchar += nums[i];
  28. while (newchar < 0)
  29. newchar += 26;
  30. while (25 < newchar)
  31. newchar -= 26;
  32. /* Set the character back to the proper ASCII value */
  33. newchar = newchar + 65 + (caps == 0 ? 32 : 0);
  34. printf("%c", newchar);
  35. }
  36. i++;
  37. if (num_elems <= i) i = 0;
  38. string++;
  39. }
  40. return 0;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement