I was trying to achieve translating a character array into a integer string and corresponding character to their alphabetical order. For instance: A(a) = 0 , Z(z) = 25.
string key_char = argv[1];
string key_num;
for (int i = 0; i < key_char.length(); i++){
if (isalpha(key_char[i])){
if (islower(key_char[i])){
key_num[i] = int(key_char[i] - 97); //97 is the ascii value for 'a'
}
else{
key_num[i] = int(key_char[i] - 65); // 65 is the ascii value for 'A'
}
cout << key_num << endl;
}
My thought was to create two strings, key_char was to store command line input from the users in characters. key_num was to store the integer string after translation. I was thinking iterating through a loop and converting each character from the character array to the integer string through casting. I didn't receive any compiling errors, and it returned nothing either. Please let me know whether the idea of casting is viable in this situation or if there's a better solution to this matter. Thank you very much!
ints or ofchars?isalphawould be false when the value isn't a letter , for example:'?'or'9'