Separating an Integer into digits

This is a discussion on Separating an Integer into digits within the C Programming forums, part of the General Programming Boards category; Hi, I am trying to discover how to find the individual digits within a number. For example, 4653 is made ...

  1. #1
    Registered User
    Join Date
    Mar 2003
    Posts
    2

    Separating an Integer into digits

    Hi,
    I am trying to discover how to find the individual digits within a number. For example, 4653 is made up from 4, 6, 5, then 3. I have been trying to work this out but have got stuck. I am sure there is a simple procedure which may have a proper name that I am unaware of so I am struggling to find information on how to do it.
    Any pointers would be very gratefully received. Thanks

  2. #2
    ggs
    ggs is offline
    C > C++ duders ggs's Avatar
    Join Date
    Aug 2001
    Posts
    435
    Code:
    digit = x % 10 + '0';
    x /= 10;    /* next digit */
    .sect signature

  3. #3
    Registered User
    Join Date
    Mar 2003
    Posts
    2

    Talking

    Thanks ggs, I have got it working now.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. memory issue
    By t014y in forum C Programming
    Replies: 2
    Last Post: 02-20-2009, 11:37 PM
  2. Link List math
    By t014y in forum C Programming
    Replies: 17
    Last Post: 02-20-2009, 05:55 PM
  3. Assignment HELP!!
    By cprogrammer22 in forum C Programming
    Replies: 35
    Last Post: 01-24-2009, 01:24 PM
  4. Looking for constructive criticism
    By wd_kendrick in forum C Programming
    Replies: 16
    Last Post: 05-28-2008, 09:42 AM
  5. load gif into program
    By willc0de4food in forum Windows Programming
    Replies: 14
    Last Post: 01-11-2006, 09:43 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21