I am trying to iterate over characters in c and really struggling to understand how to do it. I have this code which does that, however i do not completely understand it (very new to coding and C, currently taking the cs50 course).
#include <cs50.h>
#include <ctype.h>
#include <stdio.h>
#include <string.h>
int main(int argc, char *argv[])
{
// Check if there is exactly one command-line argument
if (argc != 2)
{
printf("This is an invalid keyn");
return 1;
}
// single command-line argument, case insensitive, 26 length, all letters of the alphabet only once.
int key_length = strlen(argv[1]);
// checks the length of the key to make sure it is 26 characters long
if (key_length != 26)
{
printf("Your key must contain 26 lettersn");
return 1;
}
// check if every letter of the alphabet is used.
for (int i = 0; i < key_length; i++)
{
char c = argv[1][i];
if (!isalpha(c))
{
printf("Your key must be alphabeticn");
return 1;
}
}
// Convert the key to uppercase and store it back in argv[1]
for (int i = 0; i < key_length; i++)
{
argv[1][i] = tolower(argv[1][i]);
}
//prompt user for plaintext
string plain_text = get_string("Plaintext: ");
//output ciphered text as ciphertext (currently not implemented)
return 0;
}
I have tried a few videos and articles but struggling to understand it if anyone can explain it /point me to good resources for it.