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 one character at a time from thestdinbuffer. once you are entering a character and pressing Enter then instdinbuffer 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...