Week 5 Lecture 1

Tools to help you

  • DCC Help
  • DCC Sidekick
  • https://bytesized-prod.vercel.app

Style

How to write clean code

Book suggestion

  • I don't recommend many books
  • This is a good one

1511 has a style guide

Follow the style guide (will be marked)

There is no right style guide, but you should follow it

Let's fix this up:

Command Line Arguments

So far...

  • We can pass input into functions:

    int cool_calculation(int x, int y)
  • int x, int y are the input, or arguments into the function

We can use the input to determine how the function runs

How can we do this for entire programs?

Command Line Arguments

Command Line Arguments

  • We can provide input via user input (scanf)
  • Maybe we don't want the input to come from the user, or we already have the input
  • We would like to be able to pass input to a program
  • We can modify main to allow for CLI

before

after

Quick demo

String to int

  • Sometimes we want to read in numbers
  • But all standard input is text-based
    • 6 is really "6"

Use the atoi() function to convert strings to integers

  • Stands for ASCII to Integer

    Included in stdlib.h
  • atoi(const char *str)
  • atol, atof and atoll all exist (long, float, long long)

One more thing:

  • Counting while loops is common :
  • So common, that a syntactical sugar exists that makes it a little easier

While loop

For loop

Connect 4

Feedback