I'm having trouble with this code. What case 9 is supposed to do is ask user for an index from a string and give out the ASCII integer representation of the character at the given index. While case 10 is suppose to give back instead of the default base of 10 prints out the hexadecimal representation of the character at the given index.
What case 9 is supposed to do is ask user for an index from a string and give out the ASCII integer representation of the character at the given index. While case 10 is suppose to give back instead of the default base of 10 prints out the hexadecimal representation of the character at the given index.
case'9':
{
int length = 0;
GetStringLength(pc, &length);
for(int i = 0; i < length; ++i)
{
int i_ascii = GetIntegerValueOfIndex(pc, i);
std::cout << pc[i] << "=" << i_ascii << std::endl;
// get value of i from user
// check that it is valid, or do that in the GetIntegerValueOfIndex function
// your code
std::cout << pc[i] << "=" << GetIntegerValueOfIndex(pc, i) << "\n";
}
}
Does this work? I didn't test it.
Not sure why you were looping there.
Also, it is better style to have each case call a function, unless it is a one liner.
Variables like index should be unsigned, std::size_t is a fairly normal type to use.