String to Number Conversions
Numbers can be stored either as strings or in numeric form. Storing a number as a string means storing the digit characters. For instance, the number 213 can be stored in a character string array as the digits `2', `1', `3', `\0'. Storing 213 in numeric form means storing it as, say, an int.
C requires numeric forms for numeric operations, such as addition and comparison, but displaying numbers on your screen requires a string form because a screen displays characters. The printf() and sprintf() functions, through their %d and other specifiers, convert numeric forms to string forms and vice versa. C also has functions whose sole purpose is to convert string forms to numeric forms.
Suppose, for example, you want ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access