C examples for String:char array
Returns the first non- whitespace character encountered.
#include <stdio.h> #include <ctype.h> int get_first(void); int main(void) { int ch;//from www . j av a 2s.c o m printf("Enter a line:\n"); ch = get_first(); printf("%c\n", ch); return 0; } // returns first non-whitespace character and clears remaining input until next line break or EOF int get_first(void){ int ch, garbage; do { ch = getchar(); } while (isspace(ch)); while((garbage = getchar()) != '\n' && garbage != EOF) ; return ch; }