Last active
June 10, 2017 14:28
-
-
Save MohamedTaha98/ca82295cc22f1f8cd574dc28a766d2cc to your computer and use it in GitHub Desktop.
CS50
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cs50.h> | |
#include <string.h> | |
#include <ctype.h> | |
#include <stdio.h> | |
int main (int argc, string argv[]) { | |
if (argc != 2) { | |
printf ("Please Enter 1 Key\n"); | |
return 1; | |
} | |
int key = atoi (argv[1]); | |
string s = GetString(); | |
if (s != NULL) { | |
for (int i = 0, length = strlen(s); i < length; i++) { | |
if (isalpha(s[i])) { | |
if (isupper(s[i])) { | |
s[i] -= 65; | |
s[i] = (s[i] + key) % 26; | |
s[i] += 65; | |
} | |
else { | |
s[i] -= 97; | |
s[i] = (s[i] + key) % 26; | |
s[i] += 97; | |
} | |
} | |
printf ("%c", s[i]); | |
} | |
printf ("\n"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment