Conversion Modifiers for scanf() - C Language Basics

C examples for Language Basics:scanf

Introduction

Modifier Meaning Example
* Suppress assignment (see text). "%*d".
digit(s)Sets Maximum field width. Input stops when the maximum field width is reached or when the first whitespace character is encountered, whichever comes first."%10s".
hh Read an integer as a signed char or unsigned char . "%hhd" "%hhu".
ll Read an integer as a long long or unsigned long long (C99)."%lld" "%llu".
h,l , or L Using L instead of l with e , f , and g indicates that the value will be stored in type long double. In the absence of these modifiers, d , i , o , and x indicate type int , and e , f , and g indicate type float . "%h"
jWhen followed by an integer specifier, indicates using the intmax_t or uintmax_t type (C99). "%jd" "%ju".
z When followed by an integer specifier, indicates using the type returned by sizeof (C99). "%zd" "%zo".
t When followed by an integer specifier, indicates using the type used to represent the difference between two pointers (C99)."%td" "%tx".

Example,

  • "%hd" and "%hi" indicate that the value will be stored in a short int .
  • "%ho" , "%hx" , and "%hu" indicate that the value will be stored in an unsigned short int.
  • "%ld" and "%li" indicate that the value will be stored in a long .
  • "%lo" , "%lx" , and "%lu" indicate that the value will be stored in unsigned long.
  • "%le" , "%lf" , and "%lg" indicate that the value will be stored in type double .

Related Tutorials