Please help me! Something wrong with wrapping around the keyword in my code. Here is the code:
// only one command-line argument
if (argc != 2)
{
printf("write a valid key!!!\n");
return 1;
}
// command-line argument contains only alphabetical chars
for (int c = 0, l = strlen(argv[1]); c < l; c++)
{
if (!isalpha(argv[1][c]))
{
printf("write a valid key!!!\n");
return 1;
}
}
// gets user's text
string text = GetString();
for (int i = 0, c = 0, n = strlen(text); i < n; i++)
{
// for letters
if (isalpha(text[i]))
{
// for uppercase
if (isupper(text[i]))
{
if (isupper(argv[1][c]))
{
printf("%c", ((((text[i] - 65) + (argv[1][c % strlen(argv[1])] - 65)) % 26) + 65));
}
else
{
printf("%c", ((((text[i] - 65) + (argv[1][c % strlen(argv[1])] - 97)) % 26) + 65));
}
}
// for lowercace
else
{
if (isupper(argv[1][c]))
{
printf("%c", ((((text[i] - 97) + (argv[1][c % strlen(argv[1])] - 65)) % 26) + 97));
}
else
{
printf("%c", ((((text[i] - 97) + (argv[1][c % strlen(argv[1])] - 97)) % 26) + 97));
}
}
c++;
}
// for symbols and numbers
else
{
printf("%c", text[i]);
}
}
printf("\n");
return 0;
Here is the result of check50:
Thanks in advance!