while(1)
{
if(i == 6)
break;
temp[i] = getchar();
putchar(temp[i]);
i++;
}
Whenever i had to use getchar in this way, it accepts enter also as one of the input and thus I am restrained to enter only three characters instead of 6. Why getchar takes enter as one of the input? How to avoid this?
Input:
1
2
3
After this loop breaks because the three returns pressed are considered as three inputs to temp[1], temp[3] and temp[5].
getcharreads a character at a time. On pressing Enter key you are passing newline character\nto the C standard buffer, which is also read bygetcharon next call ofgetchar. To avoid this\ncharacter you can try thisAlso read this answer to know how
getcharworks.