This program takes a command line argument of how many times you would like to encrypt plain text. After you compile the program, input a message you would like to have coded. I'm new to C and curious about how to make this program more efficient.
/*
*caesar.c
*
*
*
*Encrypts user supplied messages according to a user supplied encryption key
*
*/
#include <stdio.h>
#include <cs50.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
int main(int argc, string argv[])
{
if (argc != '\0' && argc == 2 )
{
//converting string input to integers
int f= atoi(argv[1]);
//getting string command from user
string a = GetString();
for(int i = 0, j = strlen(a); i < j; i++)
{
if ( isalpha (a[i]))
{
if (isupper(a[i]))
{
//converting capitalized chars
char acap = (a[i] - 65);
int ccap = (acap+f)%26;
//final capitalized chars loop
char ecap = ccap + 65;
printf("%c", ecap);
}
else if (islower(a[i]))
{
//converting small chars
char asma = (a[i] - 97);
int csma = (asma+f)%26;
//final small chars loop
char esma = csma + 97;
printf("%c", esma);
}
}
else
{
printf("%c", a[i]);
}
} printf("%c", esma);
return 0;
}
else
{
return 1;
}
}
cs50.h
? \$\endgroup\$