You could use an assert to see if the input to the array is ok
Here is an example:
Code:
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
//define NDEBUG
int main(int argc, const char *argv[])
{
int arr[6] = {0};
int another_arr[10] = {0,1,4,3,5,67,3,5,4,9};
int user_in;
int i;
printf(">>");
fflush(stdout);
if (scanf("%d", &user_in) == 1)
{
assert(user_in <= 10);
assert(another_arr[user_in] < 6);
arr[another_arr[user_in]] = 1;
}
for (i=0; i<6; i++)
{
printf("%d ", arr[i]);
}
fflush(stdout);
return EXIT_SUCCESS;
}
When you have finished debugging, you define NDEBUG and all the asserts go away. Note that it is bad form to keep asserts in your final code, so don't use asserts for things that may vary at run time, like the return value for malloc.