- This topic has 0 replies, 1 voice, and was last updated 3 years, 9 months ago by .
Viewing 1 post (of 1 total)
Viewing 1 post (of 1 total)
- You must be logged in to reply to this topic.
› Forums › CS50’s Introduction to Computer Science by Harvard University on Edx › Week 2: [Arrays] – Functions, Variable and Scope, Debugging, Arrays, and Command Line Arguments › How to store entered 26 character values against argv[1] to string type array key
[dm_code_snippet background=”yes” background-mobile=”yes” slim=”no” line-numbers=”no” bg-color=”#abb8c3″ theme=”dark” language=”clike” wrapped=”yes” height=”” copy-text=”Copy Code” copy-confirmed=”Copied”]
#include
#include
#include
#include
#include
int main(int argc, string argv[])
{
int counter = 0;
if (argc != 2)
{
return 1;
}
else
{
printf("enter plainkey: ");
}
string key = argv[1][];
int t = strlen(key);
if(t != 26)
{
return 1;
}
while(counter < t)
{
isdigit (argv[1][counter]);
return 1;
counter = counter + 1;
}
string s = get_string("plaintext: ");
int countstring = strlen(s);
for(int i = 0; i <= countstring; i++)
if (isalpha s[i])
{
int s[i]= int t;
t = s[i];
}
else
{
s[i] = s[i];
}
printf("ciphertext: %s",s);
}
[/dm_code_snippet]
On compiling,
![r/cs50 - How to store entered 26 character values against argv[1] to string type array key](https://i0.wp.com/preview.redd.it/56htj9ab4yg81.png?ssl=1)
There is a problem with:
string key = argv[1][ ];
How do I denote 26 characters that are supposed to be entered by the user against argv[1]. Need to store entered 26 character values to key.
Reply
You should note that agrv[1] is a string while argv[1][ ] is a character. You are declaring key as string. So you should be assigning a value of string to it and not character. Use string key = argv[1];[learn_press_profile]
