Thinking in C and *nix (CSC 295/282 2014S) : EBoards

CSC295 2014S, Class 02: Some Basic Tasks and Corresponding Tools


Overview

Preliminaries

Admin

Questions

Fun with GitHub

Go over homework

That fun hypothetical C problem. (Did anyone write code to cause

the error?)

int *x;     // Our array of data.
int 
main (int argc, char *argv[])
{
  x = malloc (...);      
  foo ();
  bar ();
  free (x);   // Crash
} // main

Spell checking

URL extraction

grep -i -o '<img[^>]*src=[^>]*>' input | grep -o '"[^"]*"'

The first part gets you lines that look like

The second part extracts the stuff in quotation marks

Flaws in this solution?

The CSV Problem

"I want the names of the people with the five highest grades on HW2." File has

fname:lname:assignment:grade

Exercise: The spaces problem

    sed -e 's/ *$//'

Write it in C. You have ten minutes.

While input characters remain read the next input character switch (ch) case space: shove it in the buffer break; case newline: clear the buffer break; default: print the buffer clear the buffer print ch; break

Raymond, chapter 1

Thinking about basic tools

Homework

  1. Learn Markdown so that we can use it for these assignments.

  2. Learn about how you set and get environment variables. Put your explanations in the submissions directory, with a file named after you.

    • Command line
    • Bash
    • C (get only)
  3. Update our list of "things every *nix user should know" (either in the repo

  4. Come up with two or three tasks, similar to those we did for assignment 1, and put notes about them in the tasks directory. (You can include some sample solutions in your file.)

  5. Read the first chapter of the Make book.

Copyright (c) 2013 Samuel A. Rebelsky.

Creative Commons License

This work is licensed under a Creative Commons Attribution 3.0 Unported License. To view a copy of this license, visit http://creativecommons.org/licenses/by/3.0/ or send a letter to Creative Commons, 543 Howard Street, 5th Floor, San Francisco, California, 94105, USA.