#include
#include
main()
{
char ch,name[20];
int i=0;
clrscr();
printf(\"Enter a string:\");
while((ch=getch())!=
An enter is actually "\r\n" (carriage return and line feed) on Windows. getchar() will return '\n' I think.
It depends on your system. Also you must know that getch() it's a part of the XSI Curses Standard issued by X-Open or OpenGroup and not related to the Borland specific conio.h header.
You must use getchar(3) or getc(3), which all of them belong to the ISO/IEC 9899:1990 standard. Both calls retreives just one byte from the controlling terminal/console or the input stream, respectively.
If you are calling them from a Windows platform, you retreive with the Enter key, the '\r', '\n' sequence, instead of just '\n'. Then you must create a loop arround the getchar(3) or getc(3) calls. Also, a call to fgets(3) over stdin would work to obtain the '\r', '\n' sequence.
Another point, is that some platforms needs flush the stding stream, then you must apply the fflush(3) call to the stdin stream.
fgets(3) and fflush(3) belongs to the ISO/IEC 9899:1990 standard.
I think it would be better to simply use:
scanf("%19s", name);
instead of getch thing.