- 01Getting Started
- 02Your First Output (printf)
- 03Working with Variables
- 04Conditionals (if statements)
- 05Loops (for statements)
- 06Writing a Function
- 07Working with Arrays
- 08Loops (while statements)
- 09Working with Structs
- 10Error Handling (Checking a Return Value)
- 11Sorting an Array (Bubble Sort)
- 12Recursive Functions
- 13The String-Handling Standard Library
- 14The switch Statement
- 15The Ternary Operator
- 16Pointer Basics
- 17Writing Comments
- 18Logical Operators (&&, ||, !)
- 19Constants (#define and const)
- 20Splitting Strings (strtok)
- 21Handling NULL Pointers Safely
- 22Searching an Array (Looping with strcmp)
- 23Transforming an Array (map-like Logic)
- 24Two-Dimensional Arrays (Tabular Data)
- 25Custom Errors (Categorizing with Error Codes)
- 26Using Variable-Length Argument Lists (stdarg.h)
- 27Removing Duplicates from an Array (Set-Like Logic)
- 28Checking Correctness with the assert Macro (Your First Step into Testing)
- 29Higher-Order Functions (Passing a Function Pointer as an Argument)
- 30Stacks and Queues (Basic Data Structures)
- 31Type Conversion (Casting) Basics
- 32Intro to Regular Expressions (regex.h)
- 33The Binary Search Algorithm
- 34Building a Caesar Cipher (a Character-Shifting Cipher)
- 35Understanding How Selection Sort Works
- 36Building and Displaying Dates (struct tm)
- 37Writing Multiple Test Cases Together
- 38Speeding Up Calculations with Memoization (Caching)
- 39Normalizing Strings (Stripping Whitespace, Unifying Case)
- 40Shallow Copy vs. Deep Copy
- 41Enum (Enumerated Types) Basics
- 42Flattening an Array
- 43Reversing a String and Checking for Palindromes
- 44Pairing Up Two Arrays (the zip operation)
- 45Rounding Numbers (floor, ceil, round)
- 46Multi-Line Strings (Adjacent String Literal Concatenation)
- 47Functions That Return Multiple Values (Structs)
- 48Finding the GCD and LCM (the Euclidean Algorithm)
- 49Formatting Numbers (Padding Digits, Decimal Places)
- 50Bundling Cleanup Logic with goto
- 51Writing Type-Agnostic Logic with Macros
- 52File Reading and Writing Basics
- 53Generating Random Numbers
- 54Bitwise Operators (AND, OR, XOR, shifts)
- 55Reading Command-Line Arguments
- 56Waiting for a Fixed Amount of Time (sleep)
- 57Watch Out for Floating-Point Rounding Errors
- 58Reading from Standard Input
- 59FizzBuzz (the Classic Practice Problem)
- 60Checking Whether a Number Is Prime
- 61Set Operations with an Array (Intersection, Difference)
- 62Converting Number Bases (Binary, Hex)
- 63Checking Balanced Parentheses (an Application of Stacks)
- 64Checking Whether Two Words Are Anagrams
- 65Checking Whether a Year Is a Leap Year
- 66Converting Temperature (Celsius to Fahrenheit)
- 67Prime Factorization
- 68[Applied] Build a Simple Grade Aggregation Program
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.
๐งช 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).
