CS 315-02 Lecture/Lab — Meeting Summary (Fall 2025)¶
- Date: Aug 28, 2025
- Time: 02:47 PM Pacific Time (US and Canada)
- Meeting ID: 868 6589 0521
Quick Recap¶
The session focused on: - C programming techniques for parsing command-line arguments and handling optional parameters. - An incremental development workflow with frequent testing and clean organization (separating concerns, using structs, and splitting code into functions/files). - Number base conversions among binary, decimal, and hexadecimal, with guidance on implementing these concepts for the upcoming project.
Next Steps¶
For Students¶
- Complete Project One by next week (base conversions and command-line argument processing).
- Implement a loop-based parser for command-line options in the echo-repeat program.
- Support optional flags:
- -h (header)
- -f (footer)
- -n
(repeat count; option with an argument) - Accept command-line arguments in any order.
- Use incremental development and frequent testing.
- Maintain consistent code style and formatting.
- Organize logic into well-named functions rather than placing everything in main.
For the Instructor (Greg)¶
- Upload the recording, notes, and code to the class website later in the evening.
- Provide a structured version of echo-repeat in the class repository demonstrating:
- Proper code organization
- Use of structs for passing data between functions
- Notify students on Campus Wire when the echo-repeat example is available.
Summary of Topics¶
C Programming: Optional Arguments and Command-Line Options¶
- The class examined how to process optional arguments and flags in C without external libraries.
- Recommended approach:
- Iterate over argv with a while loop.
- Detect options, consume their arguments (if any), set flags, and then process required arguments.
- The echo-repeat example should support -h and -f for header/footer control and -n for repeat count.
Argument Parsing Implementation Details¶
- Implementation outline:
- Iterate through argv, matching known options (-h, -f, -n).
- Set internal flags/values accordingly (e.g., enable header/footer, capture repeat count).
- Defer positional arguments until after options are processed.
- Emphasis on:
- Incremental development and testing to avoid large untested jumps.
- Conditional output behavior based on active flags.
Command-Line Processing Basics¶
- Build a simple, manual parser for flexibility and clarity.
- Write small, testable components; debug iteratively.
- Encourage questions; some topics will continue in the next session.
Code Quality and Function Design¶
- Maintain consistent formatting and syntax.
- Split responsibilities:
- Argument parsing function(s)
- Output/processing function(s)
- Use structs to pass configuration/state between functions.
- Covered representations of numbers (string vs. binary in memory).
- A structured echo-repeat example will be posted to the repository.
Number Base Conversion Techniques¶
- Reviewed conversions among decimal (base 10), binary (base 2), and hexadecimal (base 16).
- Method:
- Break numbers into components using powers of the base.
- Understand n-bit ranges and limits.
- This foundation supports accurate interpretation and display of values in different bases.
Number Conversion Project Guidance¶
- Project One:
- Convert numbers between int, bin, and hex formats.
- Preliminary task: detect input type.
- Main task: implement conversion logic.
- Organization:
- Do not place function implementations in headers.
- Use a .c source file with a .h header for declarations.
- Further modularization will come in future sessions, but it is not strictly required for this project.
Base Conversion Program Design¶
- Workflow:
- Normalize the input string to a 32-bit unsigned integer (uint32_t).
- Convert the normalized value to the requested output base.
- Input detection by prefix:
- 0b... → binary
- 0x... → hexadecimal
- No prefix → decimal
- Error handling:
- Extensive validation is not required unless specified in the assignment.
- Any extra checks must not interfere with the auto-grader or tests.
Base Conversion Process Overview¶
- Implement both directions:
- String (base N) → integer
- Integer → string (base N)
- Techniques:
- Use division and modulus for digit extraction.
- Generalize logic to support arbitrary bases where appropriate.
- Start early to avoid last-minute pressure.
- A reference echo-repeat example using a struct will be provided, along with clarified code quality expectations.
Key Takeaways¶
- Build a simple, robust command-line parser using a loop over argv.
- Keep code modular: parsing, state (struct), and output separated.
- Normalize input for conversions, then reformat to the desired base.
- Follow consistent style and develop incrementally with tests.