Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cs50.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <ctype.h>
- int main(int argc, string argv[])
- {
- string s = GetString();
- int k = atoi(argv[1]);
- if(argc != 2)
- {
- return 1; //ensures the propper amount of arguemnets
- }
- for(int i = 0; i == strlen(s); i++)
- {
- char c = s[i];
- if(isupper(c))//checks for uppercase
- {
- char caesar = (((c - 65) + k) % 26) + 65; //ciphers the text >> example (((65 - 65) + 1) MOD 26)+ 65 = 66 (B)
- printf("%c", caesar);
- }else
- if(islower(c))//checks for lowercase
- {
- char lowerCaesar = (((c - 97) + k) % 26) +65;//ciphers the text >> example (((97 - 97) + 1) MOD 26)+ 97 = 98 (b)
- printf("%c", lowerCaesar);
- }else
- {
- printf("%c", c); //prints non letters; ! , . - _ %
- }
- }
- printf("\n"); // prints the newline
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement