Intro to Programming Languages

LecLabs 2.1 C Intro and Vars

[ ← Module List ]

This module introduces the basics of Linux, including its history, architecture, and common commands. It is designed for beginners who are new to Linux and want to understand its fundamental concepts.

16 challenges

Challenges

CHALLENGE 01

Lecture 2.1.1.0 Paradigms and C

— solves

Lecture video on Paradigms and C

CHALLENGE 02

Lecture 2.1.2. First C Program and Vars

— solves

Lecture video on First C Program and Vars

CHALLENGE 03

Lecture 2.1.2.1. Standard Output

— solves

Lecture video on Standard Output

CHALLENGE 04

Lecture 2.1.2.2. Standard In

— solves

Lecture video on Standard In

CHALLENGE 05

Lab 2.1.2.1 - C Input

— solves

Objective

In this lab, you will create a program that receives multiple types of input from arguments and standard input.

CTRL-Click Here for Follow Along Video

Steps to Complete

  1. The program should implement the requirements, which are marked with //CODE:
  2. Add args, input, and output for user test 21.21.1 to test whether the program prints out argument 1 when supplied
  3. Add args, input, and output for user test 21.21.2 to test whether the program prints the correct message when 't' is provided via standard input.
  4. Make sure to use gcc main.c -g -o main.bin to compile your program
  5. Test your program from the command line and using /challenge/tester
  6. /challenge/tester will give you the flag
CHALLENGE 06

Lecture 2.1.2.3. Flow Control & Command Line Arguments

— solves

Lecture video on Flow Control & Command Line Arguments

CHALLENGE 07

EzLab 2.1.2.3 - Control Flow

— solves

Write a C program that gets a number from standard input and then prints out "I can do it!\n" that many times with each line being the count.

For example, if the input is 3 then the program will print out

I can do it!
I can do it!
I can do it!     
CHALLENGE 08

Lecture 2.1.3.0 Dec & Def Functions

— solves

Lecture video on Dec & Def Functions


int main(int argc, char *argv[]) {
    // Function body
    return 0;
}
CHALLENGE 09

Lecture 2.1.3.1. Globals & Locals

— solves

Lecture video on Globals & Locals

CHALLENGE 10

Lecture 2.1.3.2. Function Params and Ret Vals

— solves

Lecture video on Function Params and Ret Vals

CHALLENGE 11

EzLab 2.1.3.2 Pass by Value

— solves

Modify the provided main.c, to call the proper function (read the comments)

CHALLENGE 12

Lab 2.1.3.1 - Functions

— solves

Objective

In this lab, you will practice writing and using functions in C by creating a simple simulation of a galactic pizza delivery service. You will create functions to handle different aspects of the delivery process, focusing on function usage and parameter passing.

CTRL-Click Here for Follow Along Video

Requirements

  1. Define Pizza Order Variables
    • Create global variable that holds the delivery speed of 50
    • Create a local variables in main for customer1's Id, customer1's distance, make id = 1, and distance = 50
    • Create local variables in main for customer2's Id, and customer2's distance, make id = 2 and distance = 25.
  2. Functions
    • Create both a prototype (forward declaration) and a definition for each function below and place the main function inbetween them.
    • Functions to Implement:
      • void display_order(int customer_number, int distance): This function will take a pizza order's attributes as arguments and display them.
        • Print "Customer number: \n"
        • Print "Distance to customer is light years.\n"
      • double calculate_delivery_time(int distance, int speed): This function will calculate the delivery time based on distance and speed, and return the delivery time.
        • Calculate the delivery time
        • Cast the result of the calculation to a double by placing (double) before the calcuation.
        • Return the result of the calculation
      • void deliver_pizza(int customer_number, int distance, int speed): This function will simulate the pizza delivery.
        • Calculate the delivery time using the calculate_delivery_time function
        • Print "Customer 's pizza will arrive in hours!\n."
        • Use the appropriate formatter for delivery time and make sure only 2 decimal points are shown, it should look like 0.50 or 1.00.
  3. main
    • Define main
    • Add the local variables
    • For each customer: Call display order and Call deliver pizza
  4. Tests
    • Write one test following the requirements in the user test descriptions.
    • Use /challenge/tester to pass the tests and get the flag
CHALLENGE 13

Lecture 2.1.4. Global and Local Memory

— solves

Lecture video on Global and Local Memory

CHALLENGE 14

Lecture 2.1.4.1. Function Frames

— solves

Lecture video on Function Frames

CHALLENGE 15

Lecture 2.1.5. Debugging C Programs

— solves

Lecture video on Debugging C Programs

CHALLENGE 16

Lab 2.1.5.1 - Using VSCode Debugger

— solves

Using VSCode's debugger you can quickly find bugs!

Objective

We will work with the VSCode debugger to extract a few values from the program and change a variable in the middle of execution.

Review the debugger concepts below, then follow the numbered instructions in main.c to complete the lab.

CTRL-Click Here for Follow Along Video

Debugger Concepts

  • Breakpoints pause a running program before a selected line executes. Click beside a source-code line number to add or remove one.
  • Continue (F5) resumes execution until the program finishes or reaches another breakpoint.
  • Step Over (F10) executes the current line without entering a function call.
  • Step Into (F11) enters a function call so you can debug it one line at a time.
  • Step Out (Shift+F11) finishes the current function and pauses after returning to its caller.
  • The Variables section and editor hover show values that are in scope at the current execution point. Numeric values are normally displayed in decimal.
  • While execution is paused, you can double-click an editable value in the Variables section to change it.

Follow the numbered comments in main.c to complete the lab. The flag checker accepts decimal values or hexadecimal values beginning with 0x.