# Thread: Breaking an integer stored in an array into two integers

1. ## Breaking an integer stored in an array into two integers

Ok, so I understand the basics on how to split a number into two that's not my problem. A user can enter an integer and it is stored in an array. I need to take the integer from the array and split it into two halves (opCode the 1st half, memLocation the 2nd half). I put a printf statement in to track that the integer is actually being split and stored properly, and my output every time no matter what number I enter is "0 1".. I was thinking that this was maybe a pointer problem, but even when I print the pointers for these two variables they still have the same address for each number entered. I need these to be split so I can call a switch statement using the 1st half of the numbers and the 2nd half is the value that I will be passing.

I hope this makes sense, I wasn't trying to be super wordy.. Thank You!

Here's the part of my code that is relevant to this problem I am having:
Code:
```#include <string.h>
#include <stdio.h>
#include <stdlib.h>
int main(){

int memory[100];
int opCode = 0; /* variable to store first 2 digits*/
int memLocation = 0; /* variable to store end 2 digits*/

int selection = 0; /* what user will be entering into the program (ex. 1234)*/
int iCount = 0; /* Counter for the number of instructions entered */

/* -99999 is the escape*/
while (selection !=-99999){
printf("%.2d ? ", iCount);
memory[iCount] = scanf("%d", &selection);

opCode = memory[iCount] / 100;
memLocation = memory[iCount] % 100;
printf("%d\t%d\n", opCode, memLocation); /* Using this to track if the number is actually being split properly or not*/

iCount++;
}

return 0;
}```

2. Wow nevermind figured it out... I guess that's why they invented the idea of using a temp variable.

3. I've never seen "%.2d" used as a format specifier (I'm surprised it works). Usually people use "%02d" to pad with zeroes.

However, your problem is that you're putting the return value of scanf into memory. scanf's return value is the number of values scanned, which is always 1 in your case. You want:
Code:
`scanf("%d", &memory[iCount]);`

4. Yeah that may be the java programming in me but I've always had it work no problem. But thank you for the suggestion that makes so much more sense now that way