In this lab you will practice three core topics in C programming:
- Array processing (min, max, sum, average)
- Pointers as function parameters (swap, modify)
- Manual string handling (strlen, strcpy)
You will work on three separate C source files:
lab3_task1.clab3_task2.clab3_task3.c
Each file already contains:
- A comment header with your Name and Student ID to fill in
- Function prototypes
- A simple
mainwith example tests - Placeholders (
// TODO) where you need to write code
There are two ways to get the new Lab 3 files into your Codespaces.
Choose the method that fits your situation.
If you already forked the course repository in Week 1 and created a Codespace, you can simply pull the new files.
- Open your existing Codespace.
- Make sure you are on the
mainbranch from terminal:git checkout main
- Check that you have the teacher’s repository set as upstream:
git remote -vYou should see something like this in the output:
origin https://github.com/student123/RTU_Programming_Languages_C_Lab_Fall_2025.git (fetch)
upstream https://github.com/ValRCS/RTU_Programming_Languages_C_Lab_Fall_2025.git (fetch)
If you do not see upstream, add it manually:
git remote add upstream https://github.com/ValRCS/RTU_Programming_Languages_C_Lab_Fall_2025.git
4. Pull the new files from the teacher repository:
git pull upstream main
5. After this, you should see the new files:
src/lab3_task1.c
src/lab3_task2.c
src/lab3_task3.c
week3_instructions.md
If you don’t want to use terminal commands in Codespaces, you can update your fork directly on the GitHub website.
- Open your fork of the course repository on GitHub (e.g.
https://github.com/student123/RTU_Programming_Languages_C_Lab_Fall_2025). - On the repository page, you should see a “Sync fork” button near the top of the page.
- If your fork is behind the teacher’s repository, GitHub will show something like:
“This branch is 3 commits behind ValRCS:main”.
- If your fork is behind the teacher’s repository, GitHub will show something like:
- Click the “Sync fork” button, then click “Update branch” to bring your fork up to date.
- After that, go back to your Codespace and run:
git pull origin mainThis will download the updated files from your fork into your Codespace.
Use this option only if:
- You accidentally deleted your Codespace, or
- Your fork is broken and cannot be updated.
Steps:
- Go to the teacher repository.
- Click Fork to create your own copy under your GitHub account.
- When forking, GitHub may ask for a repository name.
- Example: if your GitHub username is
student123, the default fork name will be
student123/RTU_Programming_Languages_C_Lab_Fall_2025. - If you already created a fork in Week 1 or Week 2, you will need to rename this new fork (e.g.
RTU_Programming_Languages_C_Lab_Fall_2025_v2) to avoid conflicts.
- Example: if your GitHub username is
- Open the newly forked repository in GitHub and click:
Code → Codespaces → Create Codespace on main - You will now have a fresh Codespace with all files, including Lab 3. NOTE: Option A is much preferred. At some point in your future jobs you will not be allowed to just fork anytime you need a fresh copy - that is highly unprofessional.
Implement the following functions for integer arrays:
int array_min(int arr[], int size)– return the smallest elementint array_max(int arr[], int size)– return the largest elementint array_sum(int arr[], int size)– return the sum of elementsfloat array_avg(int arr[], int size)– return the average as a float
Rules:
- Do not use external libraries besides
<stdio.h>. - Write separate functions for each operation.
Example:
int arr[] = {10, 20, 5, 30, 15};
printf("Min: %d\n", array_min(arr, 5)); // 5
printf("Max: %d\n", array_max(arr, 5)); // 30
printf("Sum: %d\n", array_sum(arr, 5)); // 80
printf("Avg: %.2f\n", array_avg(arr, 5));// 16.00Practice using pointers to modify values inside functions.
void swap(int *x, int *y)– swap the values of two integersvoid modify_value(int *x)– multiply the value by 2
- Functions must modify the caller’s variables via pointers.
- Test your functions in
main.
int a = 3, b = 7;
printf("Before swap: a=%d, b=%d\n", a, b);
swap(&a, &b);
printf("After swap: a=%d, b=%d\n", a, b);
modify_value(&a);
printf("After modify_value: a=%d\n", a);Write your own versions of two basic string functions:
int my_strlen(const char *str)– return the number of characters (not counting'\0')void my_strcpy(char *dest, const char *src)– copy a string intodest
- Do not use
<string.h>functions. - Use loops or pointer arithmetic.
- Ensure
desthas enough space to hold the copied string.
char text[] = "hello";
int len = my_strlen(text); // 5
char buffer[100];
my_strcpy(buffer, text);
printf("%s\n", buffer); // hello- As usual, for each assignment submit the source code file for the assignment
lab3_task1.cfor first and so on. - Alternatively, you can also submit the link to your repository which has this MODIFIED BY YOU file. Not just my original stub..