C & C++ fundamentals / 15

Characters and strings

Read a character, introduce character arrays, and explore character-classification and conversion functions.

On this page

Now that we have finished the introductory function lessons, let's move on to characters and strings. Start by declaring a character variable with char arr;. Here is a short program that reads a character and prints it back:

#include <stdio.h>

int main()
{
    char arr;

    scanf("%c",&arr);

    printf("\n%c\n",arr);

}

Because this is a single character, we use %c. If the format specifier feels unfamiliar, revisit the earlier lesson on formatted input and output.

Character encodings

The original lesson introduces ASCII, short for American Standard Code for Information Interchange, before discussing text in English, Korean, and other languages.

Editorial correction: C and C++ are not limited to ASCII, and Korean is not part of ASCII. Text can use other encodings, including UTF-8. A char stores a byte-sized value; one char is not necessarily one complete human-readable character in a multibyte encoding.

Character arrays and strings

A string can be stored in a character array, using the arrays we learned about earlier. For example, char arr[10]; reserves ten character-sized elements. Formatted string input and output use %s rather than %c.

The original text wrote scanf("%s"&arr);. For this particular array, a bounded form is scanf("%9s", arr);: the comma is required, the array name supplies the address, and the width leaves room for the terminating null character. A ten-element array holds at most nine non-null bytes plus that terminator.

Classification and conversion

The article also introduces functions for classifying or converting individual characters:

FunctionMeaning
isupper()Is this an uppercase letter?
islower()Is this a lowercase letter?
isalpha()Is this a letter?
isdigit()Is this a decimal digit?
isalnum()Is this a letter or digit?
toupper()Convert to uppercase when possible
tolower()Convert to lowercase when possible

Pass the character value inside the parentheses, as in toupper(arr) when arr is the single-character variable from the first example.

Editorial correction: these functions are declared in <ctype.h> in C, not <stdio.h>, and they operate on character values rather than converting entire strings. The original misspelling isaplha is corrected to isalpha. Their argument must be EOF or representable as unsigned char.

The original article closes by previewing a second strings lesson. No second installment is present in the public archive being migrated.

Moved here from Tistory

I migrated this post from my Korean Tistory blog, I am Jason Lee, to this website and translated it into English. My writing and projects now live together in one place.

The original publication date, code examples, and screenshots are preserved. Editorial notes clarify known issues in the original material.

Original post on Tistory English edition · Aug 30, 2026
← Back to all articles