C/Console/Console Read Char

Материал из C\C++ эксперт
Перейти к: навигация, поиск

Get char from console and display it: getche()

  
#include <stdio.h>
#include <conio.h>
#include <ctype.h>
int main(void)
{
  char ch;
  do {
    ch = getche();
    cprintf("%c", toupper(ch));
  } while(ch != "q");
  return 0;
}


Get char from the console

  
#include <stdio.h>
int main(void)
{
  char ch;
  do {
  
    ch = getchar();
  
    putchar(".");
  
  } while(ch != "\n");
  return 0;
}


Get the next character from stdin: how to use getchar

#include <stdio.h>
int main ()
{
  char c;
  
  puts ("Enter text. "." to exit:");
  do {
    c=getchar();
    putchar (c);
  } while (c != ".");
  return 0;
}


pause until a key is pressed

#include <stdio.h>
int main() {
    puts("hello there");
    puts("what is your name?");
    
    printf("press entere to continue");
    getchar();
    puts("It is nice to meet you");
}


Read a char and check it value

#include <stdio.h>
int main(void)
{
  char ch;
  ch = getchar();
  if(ch < "h") 
      printf("character is less than h");
  return 0;
}


Read a char from console: getchar()

  
#include <stdio.h>
int main(void)
{
  char ch;
  ch = getchar(); /* read a char */
  printf("What you typed: %c", ch);
  return 0;
}


Use getchar() in for loop

  
#include <stdio.h>
#include <conio.h>
int main(void)
{
  char ch;
  for(ch = getchar(); ch != "e"; ch = getchar());
      printf("Found e.");
  return 0;
}