- This topic is empty.
Viewing 1 post (of 1 total)
Viewing 1 post (of 1 total)
- You must be logged in to reply to this topic.
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 › Understanding argv[1] and converting to integer type through Caesar and Substitution project
In Caesar project, argv[1] is a string type array that will hold key (integer value) entered by the user. Suppose the user enters 28 as key. Then:
argv[1][0] = 2
argv[1][1] = 8
argv[1][2] = ‘\0’
There was a need to convert string to integer type for argv[1][ ].
In Substitution project, argv[1] is an array of string type that will hold 26 alphabetical characters.
argv[1][0] = first character entered by the user
argv[1][1] = second character entered by the user
…………………………
argv[1][25] = 26th character entered by the user
argv[1][26] = ‘\0’
There might not be a need to convert argv[1][ ] to integer type in case it is decided to replace string characters (entered as plaintext) by matching string characters through index of argv[1][ ].
Just confirming if I am correct?
Reply
There is definitely not a need to convert it to an integer, because it is explicitly not an integer. Converting “zyxwvutsrqponmlkjihgfedcba” to an integer doesn’t make any logical sense.
Are you talking about making a new array where you get the numeric ASCII value for each character of the key entered by the user? If so, I don’t think that’s really necessary.[learn_press_profile]