Homework 3: Anagrams

This homework is to be done individually. You may ask your instructor for help, but do not ask other students, tutors, or mentors for assistance. Do NOT use solutions available on the web! You may use your textbook for help.

This program gives you more practice with strings and arrays. For hints, see King chapters 8 and 13. You will be required to write a function that passes strings (as char *) to a function in order to receive full points on the assignment.

See the "Grading" section below for specific criteria for this assignment. As with all projects and homework, the style guidelines apply to this assignment, and points may be deducted for poor style, readability, and testing. Feedback will be given using a version of this checklist.


This program will request two words (or phrases) from the user and determine if they are anagrams. Anagrams are two words or phrases that have the same letters but in different order. An example given at Wikipedia is that "listen" and "silent" are anagrams of each other. When determining if two words/phrases are anagrams, spaces and capitalization are generally ignored.

If you have trouble finding valid anagrams for testing, try using this site that has common word anagrams to help you out.

Input and Output


Your program should request two words/phrases from the user.

You can assume that each word will be no longer than 50 characters long. Words may be capitalized, but your program should ignore differences in capitalization when determining if two words are anagrams. In other words, A and a should be considered a match.

If the user enters a word containing numbers or other characters, you should accept those words, but your program should ignore numbers, spaces and other characters when deciding if the two words are anagrams.


Your program should print out both words/phrases (retaining capitalization and any extraneous characters) and print a message indicating if they are or are not anagrams.

An example of input and output:

This program will read in two words or phrases and determine if they are anagrams.

First word: Elvis
Second word: Lives

Elvis and Lives are anagrams.

This program will read in two words or phrases and determine if they are anagrams.

First word: Eleven
Second word: Twelve

Eleven and Twelve are not anagrams.

What Your Program Must Do

You can tackle this program in a few different ways. Our textbook lists one approach in the programming projects section at the end of chapter 8, but to give you more practice with functions and strings, you MUST use a function to determine if the strings are anagrams, and this function must accept two strings as parameters. So, to summarize:

  1. Must give an introductory message explaining what the program will do.
  2. Indicate to the user that they need to enter two words or phrases. Here, you need to let the user know that spaces in the word/phrase are acceptable. (My example above is NOT adequate in this regard.)
  3. Pass the two strings to a function that will determine if they are anagrams. The parameters should be char * s. The function may return a boolean or an integer.
  4. The function must not print the message about whether or not the strings are anagrams. This must be done in the main program based on the value of the boolean or integer returned by the function that analyzes the strings.


This homework programming assignment will make use of the general grading form for program style. Points may be deducted for poor programming style.

Additionally, these specific criteria will be used to grade this assignment, which is worth 25 points.