(I am using VS community, that's the reason why i used "scanf_s") I am trying to complete an assignment and i came across an issue that i couldn't solve no matter what i did. My code is =
char char_array[3];
inputchar_1D(char_array, 3);
outputchar_1D(char_array, 3);
And the functions are :
void inputchar_1D(char arr[], int size)
{
printf("\n\ninput : \n");
for (int i = 0; i < size; i++)
{
printf("\nEnter your character (%d) : ", (i));
scanf_s("%c", &arr[i]);
}
}
void outputchar_1D(char arr[], int size)
{
printf("output : \n");
for (int i = 0; i < size; i++)
{
printf("%c...\t", arr[i]);
}
}
output :
input :
Enter your character (0) :
Enter your character (1) : s
Enter your character (2) : output :
... s...
...
As you can see it is skipping the first scanf and going to 2nd one. There it asks me to write a character and once i do that it skips the 3rd one and goes to the 2nd function. Once there it prints my inputted 2nd character as the first one. The 2nd character is empty, and the 3rd character is for some reason this "╠" weird symbol. QUESTIONS :
- Why is it skipping the scanf
- Why is my character input at arr[1] printed as the arr[0]
- Why did it pass to the new line even though there is no \n
Thank you for sparing your time to help me with this...