# Thread: Better way to do this?

1. ## Better way to do this?

Is there some method to combine all these steps?

Code:
```char char2num[10];

char2num[0] = '0';
char2num[1] = '1';
char2num[2] = '2';
char2num[3] = '3';
char2num[4] = '4';
char2num[5] = '5';
char2num[6] = '6';
char2num[7] = '7';
char2num[8] = '8';
char2num[9] = '9';```

2. Code:
`char char2num[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' };`

3. Code:
`char char2num[] = "0123456789";`
That's not exactly the same, but null termination is generally useful.

4. Use a for loop to assign the values into the array. For the chars you could increment by number and then convert the number into a char. I forgot the function for that. Someone here would know.

5. Thanks for the quick replies
Works great now!

6. There are many ways:
Code:
```char whatever[10] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' };
char whatever[] = "0123456789";

char whatever[10] = {0};
for(int i = 0; i < 10; i++)
whatever[i] = i + '0';

char whatever[10] = {0};
for(char c = '0'; c <= '9'; c++)
whatever[c - '0'] = c;

// And so on..```