Ad space (banner)
๐Ÿ”งC Lessons
Lesson 64 / 68

Checking Whether Two Words Are Anagrams

This lesson covers checking whether two words are anagrams in C, so you understand a technique for comparing strings by rearranging them. It's for anyone searching "C anagram check implementation."

An anagram is a different word formed by rearranging the same letters (like "listen" and "silent"). You can check for one by rearranging both strings' characters and comparing whether they match.

The example uses the standard library function qsort() to sort the characters, defining its own comparison function, cmp(), to pass to qsort. Notice the flow of comparing the two sorted strings afterward.

A common early mistake is the syntax for qsort()'s comparison function. You need to cast a void * argument to extract its contents โ€” a distinctive style compared to other functions that takes some getting used to.

This is a basic technique for comparing strings while ignoring their character order, and it can also be applied to something like a simple cipher-solving game.

๐Ÿ“– Reference code
โœ๏ธ Your code
Type your code, then press "Run"

๐Ÿงช This site can't compile or run C directly, so it checks on the spot whether what you typed matches the reference code (scoring happens entirely in your browser โ€” nothing is sent anywhere).

Ad space (banner)
Ad space (in-article)