MP1
Coding in C with Emoji
Due dates may be found on the schedule.

This MP is all about getting conformable with memory allocation, pointers, and character encodings in C. You will complete several different sets of functions to build up your C programming skills.

1 Share your IDs

To help ensure all your work is correctly attributed to you, please fill out this form.

2 Initial Files

In your CS 340 directory, merge the initial starting files with the following commands:

git fetch release
git merge release/mp1 --allow-unrelated-histories -m "Merging release repository"

3 Machine Problem

Throughout this MP, you will be working with emojis. You will begin with some simple functions and then advance to building a small, expandable emoji translator.

3.1 Part 1: Simple Emoji Functions

In emoji.c, you will implement five functions (plus helper any functions you chose to add) that work with UTF-8 encoded strings.

3.2 Part 2: An Emoji Translator

For the second part of this MP you will create a emoji translation utility. Unlike emoji_invertChar, these translations might change the length of the string, meaning youโ€™ll need to impement some kind of data structures to support the translation.

In emoji-translate.c, you will find four functions:

3.2.1 Example Usage

emoji_t emoji;
emoji_init(&emoji);

emoji_add_translation(&emoji, "๐Ÿงก", "heart");

// The file on disk contains: "I ๐Ÿงก๐Ÿ’™ Illinois!"
unsigned char *translation = emoji_translate_file_alloc(&emoji, "tests/txt/simple.txt");

// Translation Output: "I heart๐Ÿ’™ Illinois!"
printf("%s\n");

emoji_destroy(&emoji);

3.3 Part 3: Memory Correctness

For a program to run correctly and consistently across many machines, the program must have no memory errors. Since every CPU is slightly different, a memory error may result in a program running perfectly fine on one system (perhaps the system initialized the heap memory to 0x00 for you) while may seg fault on another system (perhaps the other system has random/garbage values in the heap memory).

To test for memory correctness, we use commonly used tool called valgrind. The magic of valgrind is that it will track every memory access your program makes and report:

You will earn 67% of the credit for the MP for completing the MP. The other 33% of your grade can only be earned if your program passes all of the test cases and runs valgrind clean. To run valgrind clean, your must:

  1. Compile all test cases on the command line using make test,
  2. Run all test cases using valgrind --leak-check=full --show-leak-kinds=all ./test,
  3. Your valgrind output must report BOTH of the following:
    • All heap blocks were freed -- no leaks are possible, showing you freeโ€™d all memory before existing, AND
    • ERROR SUMMARY: 0 errors from 0 contexts, showing you made no memory errors.

Until you run valgrind clean, you should expect differences between the GitHub Action grader and your local run.

macOS Specific Information

Sadly, valgrind support on macOS is limited. However, Docker provides a Linux environment on macOS:

Build a light-weight docker
docker build -t cs340 .
Run make clean to clear any old compiled code that may be compiled outside of docker
docker run --rm -it -v "`pwd`":/mp1 cs340 "make clean"
Run make test to compile the test case inside of docker
docker run --rm -it -v "`pwd`":/mp1 cs340 "make test"
Run valgrind ./test to run the test case with valgrind inside of docker
docker run --rm -it -v "`pwd`":/mp1 cs340 "valgrind ./test"

Alternatively, you can copy your code to your course VM and run valgrind there.

4 Modifiable Files

In your solution, you must only modify the following files. Modifications of other files may break things:

5 Testing Your Program

6 Submission and Grading

6.1 Testing Suite

When you are finished working on the MP, you can run a local copy of the same test suite that you will use for grading. To run the test suite:

6.2 Submission

Once you have locally passed all the tests, you will need to submit and grade your code. First commit using the standard git commands:

git add -A
git commit -m "MP submission"
git push

6.3 Grading

The initial grading is done via a manual GitHub Action. You MUST complete this step before the deadline to earn any points for the MP:

6.4 Weight

Autograding is given 2/3 weight for this MP.

Valgrind is given 1/3 weight for this MP.