i'm new to this and CS50.
int main(int argc, string argv[]) { if (argc <= 1 || argc > 2) { printf("Open program with a key!!!\n"); return 1; }
int k = atoi(argv[1]);
if (k < 0)
{
printf("Give me a positive Int!!!\n");
return 1;
}
string msg = GetString();
for (int i = 0, s = strlen(msg); i < s; i++)
{
if (isspace(msg[i]))
{
printf(" ");
}
else if (msg[i] == 33)
{
printf("%c", msg[i]);
}
else if (msg[i] == 44)
{
printf("%c", msg[i]);
}
int c[i];
if (isalpha(msg[i]))
{
if (isupper(msg[i]))
{
c[i] = msg[i] - 'A';
c[i] = (c[i] + k) % 26;
c[i] = c[i] + 'A';
printf("%c", toupper(c[i]));
}
else if (islower(msg[i]))
{
c[i] = msg[i] - 'a';
c[i] = (c[i] + k) % 26;
c[i] = c[i] + 'a';
printf("%c", tolower(c[i]));
}
}
}
printf("\n");
return 0;
}
Can someone please tell me the more refined way I could of done it please, as I just want to know for the future.
Thanks