CS 0449 – Project 1: Craps & ID3 Tags

Due: Sunday, February 6, 2011, at 11:59pm

Your first project is to write two programs in C that provide some experience with a wide range of the topics we have been discussing in class.

# The Game of Craps (30 points)

For the first part of this project, you will be implementing the game of Craps. For those unfamiliar with the rules, Craps is played with two dice which are rolled together. The sum of these two dice is computed and if the sum is:

·         2, 3, or 12 – the player immediately loses.

·         7 or 11 – the player immediately wins.

·         Any other number is referred to as the “point.” The goal then becomes to keep rolling the dice until:

o   The player rolls a 7 – the player loses

o   The player rolls the “point” – the player wins.

Your job on this assignment is to make a simple craps game.  In this game the player will enter his or her name, the program will display a welcome message, and ask if the player would like to play or quit.  The program will then roll two dice, and display them and their total.  If the player has won, display a message congratulating them. If the player has lost, report it to them. Otherwise, store this first roll as the “point” roll and keep rolling until the player wins or loses.  When the game ends, ask if the player would like to play again. Example:

Welcome to Jon’s Casino!

Jonathan, would you like to Play or Quit? play

You have rolled 5 + 2 = 7

You Win!

Would you like to play again? no

Goodbye, Jonathan!

## Hints

• Generating random numbers in C is a two-step part. First, we need to seed the random number generator once per program. The idiom to do this is:
srand((unsigned int)time(NULL));
• When we need random numbers, we can use the rand() function. It returns an unsigned integer between 0 and RAND_MAX. We can use modulus to reduce it to the range we need:
int value = rand() % (high - low + 1) + low;
• Remember that rolling two 6-sided dice is different than rolling one 12-sided die.

# ID3 Tag Editor (70 points)

An ID3 version 1.1 tag for MP3s (and other multimedia files) adds metadata describing the file. The contents of an ID3 tag are the following:

 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 A one-byte separator (always 0) 126 1 Track number byte 127 1 Genre identifier byte

An ID3 (v1.1) tag like above is appended to a file as the last 128 bytes. The tag is present if at the -128 from end offset there are the three ASCII characters TAG.

## What To Do

For your project you will make a utility that can print the contents of an existing tag, if there, and add or modify a tag.

Make a program called id3tagEd and make it so that it runs with the following command line options:

id3tagEd FILENAME

should print the contents of the ID3 tag to the console if present, or give a message if not present

id3tagEd FILENAME -FIELD VALUE

should set the specified field to the value that follows it.

You should handle the following field names (specified in lowercase):

·         Title

·         Artist

·         Album

·         Year

·         Comment

·         Track

Make sure you are able to handle multiple {field, value} pairs on the command line at once. If the tag already exists in the specified file, then edit it, if not create a new tag by appending a tag at the end with the specified fields populated. Assume all others are to be empty (filled with 0 bytes.)

## Hints and Requirements

• The strings may not have a null-terminator. Be careful that you do the right thing in these cases. Look into the strn family of functions.
• We need to treat these files as binary files rather than text files. Make sure to open the file correctly, and to use fread and fwrite for I/O.
• Please use a structure to represent an ID3 tag rather than a bunch of disjoint strings. Do your fread() and fwrite() with the whole structure at once.
• Note that you do NOT need to handle the genre field. Just leave it unchanged if editing, and make it 0 if making a new tag.
• atoi() from <stdlib.h> converts a string to an integer in the fashion of Integer.parseInt()

# Environment

Ensure that your program builds on thot.cs.pitt.edu as that will be where we are testing.

If you are running low on AFS space, we’ve provided you a directory on the local harddrive at /u/SysLab/USERNAME where USERNAME is your Pitt user id. Note though that this directory is not backed up, so please save your work in AFS or somewhere else. Lost work due to machine failure is not grounds for an extension.

# Submission

When you’re done, create a gzipped tarball (as we did in the first lab) of your commented source files and compiled executables and copy them to:

~jrmst106/submit/449/