-5

I'm taking in input from the user as a string. I want to transfer the input to an integer array. I'm using atoi, but it places the entire input from the user into each part of the integer array. How do I get this to happen:

string input = 12345
array[0] = 1
array[1] = 2 
array[2] = 3
etc.

Instead of:

string input = 12345 
array[0] = 12345
array[1] = 12345
array[2] = 12345
etc.
Jabberwocky
  • 48,281
  • 17
  • 65
  • 115
Katy
  • 13
  • 2

1 Answers1

1

In stead of using atoi you should convert each digit separately to an integer value and place it in the array.

As a normality of ASCII, the ASCII digits are consequtive, so you can use:

    char c = '9';
    array[1] = c - '0';

As this smells of homework, I leave the rest to you. I hope this helps.

Paul Ogilvie
  • 25,048
  • 4
  • 23
  • 41