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].
getchar
reads one character at a time from thestdin
buffer. once you are entering a character and pressing Enter then instdin
buffer two characters are getting stored.if you want to enter six character by using your code then enter all characters at once and then press enter it will work. otherwise you will have to skip 'Enter' character. like this...