Hi everyone,
I'm trying to store user input into an array.
The output looks like this:
Enter the size of the arrays:
5
Enter the cells of array1:
1 2 3 4 5
Enter the cells of array2:
5 4 3 2 1
This is my code so far:
int main() {
int size, eleOne, eleTwo;
int i=0, j=0;
printf("Enter the size of the arrays: \n");
scanf("%d", &size);
int array1[size];
int array2[size];
int c = getchar();
printf("Enter the cells of the first array: \n");
while ((i < size-1) && (c != EOF)) {
array1[i] = c;
i++;
c = getchar();
}
printf("Enter the cells of the second array: \n");
while ((i < size-1) && (c != EOF)) {
array2[j] = c;
j++;
c = getchar();
}
}
First of all, the numbers can be any length. If the input is size 5, the cells could be "500000 500000000 123232 23232323 5000000". The space of course tells us the number has ended and that the number needs to be stored in the first cell of the array, but I am not sure how to program that. Any ideas? Thanks very much!