Advertisement
Guest User

Untitled

a guest
Jun 28th, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <cs50.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. #include <ctype.h>
  6.  
  7.  
  8. int main(int argc, string argv[])
  9. {
  10.  
  11. int decoder;
  12. int result;
  13.  
  14.  
  15. if (argc != 2)
  16. {
  17. printf("Please enter more arugments.\n");
  18. return 1;
  19. }
  20.  
  21.  
  22. string PlainText = GetString();
  23.  
  24.  
  25. decoder = atoi(argv[1]);
  26.  
  27.  
  28. if (decoder >= 26)
  29. {
  30. decoder = (decoder % 26);
  31. }
  32. for(int i = 0, length = strlen(PlainText); i < length; i++)
  33. {
  34. result = (PlainText[i] + decoder);
  35. if (isupper(PlainText[i]) && (result > 'Z'))
  36. {
  37. result = (result - 26);
  38. }
  39. if (islower(PlainText[i]) && (result > 'z'))
  40. {
  41. result = (result - 26);
  42. }
  43. if (isalpha(PlainText[i]))
  44. {
  45. printf("%c", result);
  46. }
  47.  
  48.  
  49. else
  50. {
  51. printf("%c", PlainText[i]);
  52. }
  53.  
  54. }
  55.  
  56. printf("\n");
  57. return 0;
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement