IT, Programming, & Web Development › 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
- This topic is empty.
-
AuthorPosts
-
February 11, 2022 at 5:41 am #209
[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,
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 whileargv[1][ ]
is a character. You are declaring key as string. So you should be assigning a value of string to it and not character. Usestring key = argv[1];
[learn_press_profile] -
AuthorPosts
- You must be logged in to reply to this topic.