I am trying to write a program that takes a 10 digit phone number and inserts hyphens between the 3rd and 4th digit and the 6th and 7th digit
eg. Enter phone number: 5553459875
Your number is 555-345-9876
I've decided that reading the number as an integer won't work and tried reading each as a char but then it still doesn't print how I want it to
Any help would be appreciated
Thanks
Seems to me like your process is this...
- You need a character array of length 13 or more.
- Assume it currently contains the ten digits, plus a NULL terminator at index 10.
- You want to stick a hyphen at index 3. That means you need to move the data at indexes 3 to 10 to 4 to 11. Use the memmove function from string.h to move those 8 bytes one byte to the right.
- Make index 3 a dash.
- Same process for index 7. It needs to be a dash, so you need to move bytes 7 through 11 to bytes 8 thorough 12. Again, use memmove to move those five bytes one byte to the right.
- Make index 7 a dash.
- Done!
VernonDozier
Posting Expert
5,675 posts since Jan 2008
Reputation Points: 2,633
Solved Threads: 738
Skill Endorsements: 18
Question Answered as of 1 Year Ago by
VernonDozier