How do I ask for an input (ex:123456) into an integer array so that it is 1,2,3,4,5,6 in the array without using any punctuations or spaces?
int main(void)
{
int input[7] = {0};
printf("");
scanf("%d%d%d%d%d%d", &input);
}
>Solution :
scanf() can’t read directly into an array (except for strings), it requires a separate argument for each value you’re reading.
And to read each digit separately without any delimiters, you have to specify the field size in the format string.
scanf("%1d%1d%1d%1d%1d%1d", &input[0], &input[1], &input[2], &input[3], &input[4], &input[5]);
You can also use a loop:
for (int i = 0; i < 6; i++) {
scanf("%1d", &input[i]);
}