Thanks to Dr. Misurda for project concepts and portions of the writeup.

[30%] mastermind.c

Maybe you’ve played this game before, maybe not. Here’s a link to an online version. When you put in your guess:

How your version will work

  1. Ask the user how many colors (3 to 6).
    • Keep asking until they type in a valid number.
    • This lets them choose the difficulty of the game.
  2. Generate a random sequence of 4 colors, where each item of the sequence can be one of:
    • 3 colors: { red, green, blue }
    • 4 colors: { red, green, blue, yellow }
    • 5 colors: { red, green, blue, yellow, purple }
    • 6 colors: { red, green, blue, yellow, purple, orange }
    • Colors may repeat! So even red-red-red-red is valid.
  3. Give the user at most ten guesses as follows:
    • Read a guess from the user as a sequence of 4 letters which represent colors.
      • Keep asking until they type in a valid guess.
    • Check their guess.
    • Tell the user how many of each kind they have:
      • correct color in the correct place
      • correct color in the wrong place
    • If they won:
      • ask them if they want to play again. If so, go back to the very beginning.
  4. If they don’t get it in 10 guesses:
    • tell them the solution
    • ask them if they want to play again. If so, go back to the very beginning.

Reading and displaying the colors

The colors will be represented as lowercase letters.

So if the player enters rggb, that means red-green-green-blue.

If the player enters anything other than 4 letters, or if they use any invalid letters (e.g. trying to guess orange when they are playing a 3-color game, or using any other letters), it’s an invalid guess, and you should ask them again.

When you display the solution, you should use these letters as well.


The atoi() function from <stdlib.h> will parse an integer from a string. Be sure to read its documentation to know how it works.

Feel free to use any example code I have given you. Things like read_line, streq etc will be helpful.

Do not add extra prompts/questions, and do not be too picky about user input. Accept lower- AND upper-case letters for the colors. User experience is an important part of program design! And it will make it faster and easier to grade your projects ;)

To generate random numbers:

This method will generate slightly biased results and should not be used to generate a range of random numbers in general. For something this simple, it’s fine.

[70%] id3edit.c

Who remembers MP3s? No? No one? My god I’m old.

ID3 is a standard way of embedding song information in an MP3 file, so it can store the album, artist, song name etc. That’s how iTunes or your MP3 player or your phone knows.

You will make a utility that can:

ID3 tag structure

An ID3 tag is a binary structure which looks like this (offsets and lengths are measured in bytes):

Offset Length Description
0 3 “TAG” identifier string
3 30 Song title string
33 30 Artist string
63 30 Album string
93 4 Year string
97 28 Comment string
125 1 Zero byte separator
126 1 Track number byte
127 1 Genre identifier byte

When translating this to a C structure, come up with appropriate types for each field. The size of the entire ID3 tag struct should be 128. You can use sizeof() to find out.

The string fields may or may not have zero terminators at the end. See the Hints section.

Where’s the ID3 tag?

The ID3 tag does not appear at the beginning of the file, but rather at the very end. In other words, f your structure is named ID3Tag, then it is -sizeof(ID3Tag) bytes from the end.


I will provide you with some test MP3 files to use. But we will test your program with more.

You can copy them to your directory like so:

cp ~jfb42/public/cs449/*.mp3 .

Don’t forget the space and period in the above command.

If you mess up or corrupt the files somehow, don’t worry, just run this command again to get clean copies of them.

The files should have the following fields by default:

How it will work

$ ./id3edit

This should display a help message explaining how to use the program.

$ ./id3edit FILENAME

This should try to read the given file, and display its ID3 tag contents if it has one, or say that it doesn’t have one.

$ ./id3edit FILENAME -field value

This will set one of the ID3 tag’s fields to “value,” where “field” can be one of:

So an example might be ./id3edit test.mp3 -year 1988

$ ./id3edit FILENAME -field value -field value
$ ./id3edit FILENAME -field value -field value -field value
$ ./id3edit FILENAME -field value -field value -field value -field value

Your program should also allow any number of fields to be set at once.

Program behavior



We will be compiling your programs with the following options, so be sure to compile with them while you develop as well:

$ gcc --std=c99 -Wall -Werror -o mastermind mastermind.c
$ gcc --std=c99 -Wall -Werror -o id3edit id3edit.c


Follow this checklist:

Never turn in a program that doesn’t compile.

If you answered yes to all those questions, then you can submit using the same directions as lab1.