A repository of exercises to support the training.
Welcome to Module 01 of Advanced C Programming! In this module, you'll learn how to define and optimize data structures, write functions, and organize code for a smart home system using C programming. We'll guide you through various exercises and a lab assignment to reinforce your understanding of these concepts.
Before beginning these exercises, make sure you have:
In this exercise, you will create a struct to represent a smart device, such as a smart light. You will initialize it with sample data and prepare it for use in the program.
Instructions:
struct for a smart device, such as a smart light.deviceID, status, brightness, and color.Example Code:
#include <stdio.h>
// Define a struct for a smart light device
struct SmartLight {
int deviceID; // Unique identifier for the device
char status[10]; // Status of the light (e.g., "ON", "OFF")
int brightness; // Brightness level (0 to 100)
char color[20]; // Color of the light (e.g., "Warm White", "Cool White")
};
int main() {
// To do: Initialize the struct with sample data
// To do: Print the smart light details
return 0;
}
Memory optimization is crucial in embedded systems. In this exercise, you will learn how to arrange struct fields to minimize padding and optimize memory usage.
Instructions:
Note:
To verify the size of a struct in C, you can use the sizeof operator.
Writing functions to control devices is an essential part of smart home systems. In this exercise, you will create a function to control a smart light's state.
Instructions:
Smart home systems often read data from multiple sensors. In this exercise, you'll learn how to handle multiple return values using a struct.
Instructions:
struct to hold multiple sensor readings (e.g., temperature, humidity, motion).Proper code organization is key for maintainability. In this exercise, you will organize the code you've written so far into multiple files.
Instructions:
.c and .h files for different parts of the code (e.g., main, device control, sensor handling).Note:
Code that is related to device should be in device.h/.c.
Smart devices need to communicate with each other or with a central hub. In this exercise, you will create a communication module for your smart home system.
Instructions:
.h) and source (.c) files.Now that you've completed the individual exercises, it's time to put everything together!
Objective: Create a complete program that simulates a smart home system, integrating all the concepts you've learned. You'll combine your structs, functions, and modules to build a cohesive and functional system.
Deliverables:
Next Steps: Continue to enhance your smart home system by adding new features, such as communication protocols, real-time monitoring, or user-friendly controls. Stay curious and keep experimenting!
Happy coding!