Thread: Convert Integer into an array

  1. #1
    Registered User
    Join Date
    Nov 2005

    Convert Integer into an array

    I need help converting an integer into an array. Basically, I have a 5 digit integer, lets say its 78722, and I need to convert it into an array that looks like this: [7] [8] [7] [2] [2]

    In other words, array[0]=7, array[1]=8, array[2]=7, array[3]=2, and array[4]=2

  2. #2
    Registered User TactX's Avatar
    Join Date
    Oct 2005
    What type does the destination array have? Do you need a string? Then look up snprintf()

  3. #3
    Registered User
    Join Date
    Aug 2005
    New Delhi
    All you need to do is keep dividing the number by 10, your remainder will be the LSD from the integer then store the digits in reverse order.

    Thus if you have a 4 digit number, the remainder you get after your first division must goto array[3].

    That's the maximum help I can give you without you writing your own code, work it out on paper before writing the program and i'm sure it wont be a problem.
    Last edited by sahil_m; 11-08-2005 at 10:33 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 07-11-2008, 07:39 AM
  2. No Match For Operator+ ???????
    By Paul22000 in forum C++ Programming
    Replies: 24
    Last Post: 05-14-2008, 10:53 AM
  3. convert 2D array into 1D array
    By coolvik87 in forum C Programming
    Replies: 4
    Last Post: 08-01-2006, 09:51 AM
  4. load gif into program
    By willc0de4food in forum Windows Programming
    Replies: 14
    Last Post: 01-11-2006, 10:43 AM
  5. char array string > integer
    By luigi40 in forum C Programming
    Replies: 2
    Last Post: 06-03-2004, 11:28 AM