class: title # Debugging Practice ## CSC 213 – September 2, 2026 --- # Agenda for Today 1. Upcoming Work 2. C Practice 4. Debugging 5. Wrap Up --- class: section, blue # Upcoming Work --- # Assignment 1: Ngram Generator **Due:** Tuesday, September 8th by 11:59pm ## Questions *None so far.* --- class: section, green # C Practice --- # C Practice: The Problem We are going to write a C program called `charsort` together as a class (I will drive). The program should do the following: 1. The program must accept exactly one string as a command line argument. 2. The output should be all of the letters in the input string, but printed in sorted order. For example: ```shell $ ./charsort hello ehllo ``` Take a minute to consider how you might approach this problem and what you might need to look up to implement your approach. --- class: section, gray # C Practice: Live Coding --- # C Practice: Style Guide Good C code should do the following: .left-col[ - Indent every block of code - Always use curly braces around blocks - Write explanatory comments, with at least one by each block of code - Cite resources in comments next to the relevant code - Use descriptive variable names - Use whitespace to break code into logical chunks - Validate user input - Print helpful error messages ] .right-col[ - Use standard library functions instead of re-implementing them. - Try to follow modern C conventions - Check return values from library functions - Fix code that generates compiler warnings - Use resources, and cite them appropriately - Use local memory whenever possible (instead of calling `malloc`) - Free allocated memory when you are done with it ] -- **Is this list missing anything?** --- class: section, blue # Debugging --- # Discussion: Debugger Commands For each `gdb` command below: what does it do, and when would you use it? - `start` - `continue` - `break` - `watch` - `step` - `next` *Start by thinking of answers on your own. I will let you know when to start discussion.* --- class: section, green # Debugging Exercise --- class: section, blue # Wrap Up --- # Reminders ## Assignment The Ngram Generator assignment is due on Tuesday evening. Start early so you have time to get stuck. ## Reading - **The Abstraction: The Processes** (OSTEP, Chapter 4) - **Interlude: Process API** (OSTEP, Chapter 5) - **Mechanism: Limited Direct Execution** (OSTEP, Chapter 6)