I'm trying to cast a character within a string which is stored in argv[1]
and an int variable named k
that will have its corresponding ASCII
value.
Furthermore, this character which I'm casting will also be continuously changing by the means of a for loop controlled by another int variable named c
. I am posting the code below.
Let me know, what I'm doing wrong because I keep getting many different error messages.
#include <stdio.h>
#include <cs50.h>
#include <ctype.h>
#include <string.h>
#include <stdlib.h>
int main(int argc, string argv[])
{
int a = argc;
if (a != 2)
{
return 1;
}
string b = argv[1];
//b IS THE CODE WORD
string ptext;
//ptext IS THE MESSAGE TO BE ENCRYPTED
if (isalpha(b))
{
ptext = GetString();
}
else
return 1;
//this is to index the letters within the code word
for (int c = 0, d = strlen(b); c < d; c++)
{
int k = (b(char[c]));
//this is to index the letters within the plaintext
for (int i = 0, l = strlen(ptext); i < l ;i++)
{
while (isalpha(ptext[i]))
{
printf("%c", b[c]%d+k);
}
}
}
}
The part in question is 11 lines from the bottom .