How to use getchar() function to get character from stdin in C

1 Answer

0 votes
#include <stdio.h>
   
int main(void)
{
	int ch;
	puts ("Enter text '*' + Enter to exit:");
	do {
		ch = getchar();
		putchar(ch);
	} while(ch != '*');
	
    return 0;
}
  
/*
run:
  
Enter text '*' to exit:
hello getchar *
hello getchar *

*/

 



answered May 5, 2016 by avibootz

Related questions

...