I'm trying to put another statement to end the while-loop with logical AND:
while ( (character != '\n') && ( i < 10 ) )
...the extra +10:th letters does not get stored in the array. But I can still type in input until pressing ENTER / '\n' .
What am I doing wrong? What happens with the 'extra input'?
This is the code:
char character;
char buffer[81];
int i = 0;
do
{
character = getchar();
buffer[i] = character;
++i;
} while ( (character != '\n') && (i < 10) );
buffer[i-1] = '\0';