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


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...

  1. You need a character array of length 13 or more.
  2. Assume it currently contains the ten digits, plus a NULL terminator at index 10.
  3. 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.
  4. Make index 3 a dash.
  5. 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.
  6. Make index 7 a dash.
  7. Done!

exactly the kind of help i was looking for. thank you i will get right on it

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.