Use scanf() to read Individual Characters - C Language Basics

C examples for Language Basics:scanf

Introduction

When using scanf() to read a single character, use the %c format specifier.

scanf with %c reads input character by character, even for the spaces, tabs, and newlines which are used as field separators.

For example, with an input stream of "x y" this code fragment

scanf("%c%c%c", &a, &b, &c);

returns with the character x in a, a space in b, and the character y in c.


Related Tutorials