How can I manipulate strings of multibyte characters?

Say your program sometimes deals with English text (which fits comfortably into 8-bit chars with a bit to spare) and sometimes Japanese text (which needs 16 bits to cover all the possibilities). If you use the same code to manipulate either country’s text, will you need to set aside 16… Continue reading

What are multibyte characters?

Multibyte characters are another way to make internationalized programs easier to write. Specifically, they help support languages such as Chinese and Japanese that could never fit into eight-bit characters. If your programs will never need to deal with any language but English, you don’t need to know about multibyte characters…. Continue reading

What math functions are available for integers? For floating point?

The operations +, –, *, and / (addition, subtraction, multiplication, and division) are available for both integer and floating-point arithmetic. The operator % (remainder) is available for integers only. For floating-point math, many other functions are declared in the header file math.h. Most of these functions operate in double-precision floating… Continue reading

Why shouldn't we start variable names with underscores in C?

Identifier names beginning with two underscores or an underscore followed by a capital letter are reserved for use by the compiler or standard library functions wherever they appear. In addition, all identifier names beginning with an underscore followed by anything are reserved when they appear in file scope (when they… Continue reading

What is a "locale"?

A locale is a description of certain conventions your program might be expected to follow under certain circumstances. It’s mostly helpful to internationalize your program. If you were going to print an amount of money, would you always use a dollar sign? Not if your program was going to run… Continue reading

How do I determine whether a character is numeric, alphabetic, and so on?

The header file ctype.h defines various functions for determining what class a character belongs to. These consist of the following functions: Function Character Class Returns Nonzero for Characters isdigit() – Decimal digits – 0-9 isxdigit() – Hexadecimal digits – 0-9, a-f, or A-F isalnum() – Alphanumerics – 0-9, a-z, or… Continue reading

What is the difference between a free-standing and a hosted environment?

Not all C programmers write database management systems and word processors. Some write code for embedded systems, such as anti-lock braking systems and intelligent toasters. Embedded systems don’t necessarily have any sort of file system, or much of an operating system at all. The ANSI/ISO standard calls these “free-standing” systems,… Continue reading

What header files do I need in order to define the standard library functions I use?

The funny thing is, these are not necessarily the files that define what you’re looking for. Your compiler guarantees that (for example) if you want the EDOM macro, you can get it by including <errno.h>. EDOM might be defined in <errno.h>, or <errno.h> might just include something that defines it…. Continue reading

Why should I use standard library functions instead of writing my own?

The standard library functions have three advantages: they work, they’re efficient, and they’re portable. They work: Your compiler vendor probably got them right. More important, the vendor is likely to have done a thorough test to prove they’re right, more thorough than you probably have time for. (There are expensive… Continue reading