Using getch() to input strings and read Non-ANSI code, \r - C Data Type

C examples for Data Type:char

Description

Using getch() to input strings and read Non-ANSI code, \r

Demo Code

#include <stdio.h>
#include <conio.h>

#define MAX 80/*  ww w  . j  a va2  s.  c o m*/

int main( void )
{
     char ch, buffer[MAX+1];
     int x = 0;

     while ((ch = getch()) != '\r' && x < MAX)
         buffer[x++] = ch;

     buffer[x] = '\0';

     printf("%s", buffer);

     return 0;
}

Result


Related Tutorials