I have the following code that displays up to a char level. I need to write a program where the user will enter letters as a phone number and it will convert the letters into digits. FYI - I have tried few times with the string, but no luck. Please guide me as to how I should proceed with the strings, and get character by character. Thanks in advance!
Only allows you one char. You really need to do an array of char and then do a loop to go through each spot in the array to change each letter one at a time. If you turn your switch into a function which takes in one char and returns one number then you can pass each char to the function one at a time.
char word[11]; // Max size of phone number is 10 the 11th char will be '\0' which indicates the end of the array
Thanks for the response Ryan!
I have been trying since then on what you said.Currently I am completely lost. Can you please provide me with an example of when you say - " You really need to do an array of char and then do a loop to go through each spot in the array to change each letter one at a time. If you turn your switch into a function which takes in one char and returns one number then you can pass each char to the function one at a time."
FYI - when i build the program now, i get the following error message.
'char [11]' differs in levels of indirection from 'int'
Well, the loop seems to be working. I am trying to put hyphen between numbers, but am not able to do so. I did try using if statement, as you can see in the code below. the hyphen shows at the beginning of the next loop, but not after the third letter in the phone number. For example, 222-2222 Can you please let me know where it suppose to go. Thanks!