Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include <stdio.h>
- #include <cs50.h>
- #include <ctype.h>
- #include <string.h>
- int main (int argc ,char* argv[])
- {
- if (argc != 2)
- {
- printf("Try again");
- return 1;
- }
- int key = atoi(argv[1]); /// Get key turn it into an Int
- string p = GetString();
- char sum[strlen(p)]; /// Declare the string length of p as char
- for ( int i = 0, n = strlen(p);i < n; i++) /// Iterate over the string length of p and print enciphered code
- {
- if isalpha(p[i])
- {
- if isupper(p[i])
- {
- sum[i] = (p[i] - 'A' + key) % 26 + ('A');
- }
- else if islower(p[i])
- {
- sum[i] = (p[i] - 'a' + key) % 26 +('a');
- }
- else
- {
- sum[i] = p[i];
- }
- }
- }
- printf("%s\n",sum);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement