# Thread: input row of integers via scanf into an array...

1. ## input row of integers via scanf into an array...

that make sense? How should I go about doing this...?

Essentially I want to be able to input 11 single digit numbers (ie from 0-9) and store them in an array. Once I have that I can start looking at the second step, which complicates things by calculating the highest number, then printing the difference between that and the printed number...

eventually I'd like to be able to input say: 56784321908 and have it see that 9 is the highest value and thus subtract the numbers away from 9 so it prints: 43215678091.

I'll work on that later, but right now I'm just stumped as to how to input a bunch of numbers via a scanf and put them into an array.
Code:
```scanf( "%11d", &array[11] ) ;
/* Initial Idea for 11 digits */```
hoping that if I then made an array:
Code:
`int array[11]`
that might lead to something... but then got to thinking do I infact want:
Code:
`scanf( "%1d%1d%1d%1d%1d%1d%1d%1d%1d%1d%1d", &array[11] ) ;`
? I still can't actually seem to figure out how I get the numbers into the array... do I have to list it out like:
Code:
```int a[11]
a[0] = '_' ;
a[1] = '_' ;
a[2] = '_' ;
a[3] = '_' ;
a[4] = '_' ;
a[5] = '_' ;
a[6] = '_' ;
a[7] = '_' ;
a[8] = '_' ;
a[9] = '_' ;
a[10] = '_' ;```
? If so what do I but between the ' 's?

This must be a simple thing: How to input a line of single digits and save them into an array, to later be called. But this is the only idea I have so far, and most tutorials/lecture slides/text books either work with letters, and changing case, or single inputs, not a bunch of them.

Completely stumped. I don't have a piece of code to post for corrections, I'm just trying to get my head around this idea, so any help, or points in the right direction would be ace.

Thanks,

2. >How should I go about doing this...?
Keep it simple. scanf requires very strict formatting, but your problem doesn't provide that formatting. So what you need to do is take each digit as a character and add it individually to your array in a loop (after converting it to the integer representation of that character, of course):
Code:
```for ( i = 0; i < 11; i++ ) {
int ch = getchar();

if ( !isdigit ( ch ) )
break;

array[i] = ch - '0';
}```