I tried to make program to take some integers and write them in reversed order. When I input value for scanf_s program requires one more input and then moves on. Looks like that program does not write and read properly from and to memory. Code:
#include <stdio.h>
#include <stdlib.h>
void readValues(int * arr, int * size) {
while (arr != size) {
printf("Input number: \n");
scanf_s("%d ", arr);
arr++;
}
}
void printReversed(int * arr, int * size) {
while(size != arr) {
printf("%d ", *size);
size--;
};
}
int main() {
int n;
printf("Input number of values to read: \n");
scanf_s("%d\n", &n);
int * arr = (int*)malloc(n * sizeof(int));
int * size = arr + n;
readValues(arr, size);
printReversed(arr, size);
free(arr);
}