0

In the following code, the first section inserts the user input into the array, However, the second section inserts automatically a null after the character input and takes the memory place of two characters(one for input and the second for null).

int numArray[5];
for(int i=0; i<5; i++)
{
  printf("insert number %d:", (i + 1));
  scanf("%d", &numArray[i]);
}


char chArray[5];
for(int i=0; i<5; i++)
{
  printf("insert character %d:", (i + 1));
  scanf("%c", &chArray[i]);
}

I am aware of the method of inserting the characters by string input for example (input: abcde) will insert the characters to the array, but I would love to hear if there is a method to get the input of a single character at a time and insert it into the array?

Jabberwocky
  • 48,281
  • 17
  • 65
  • 115

0 Answers0