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;
}