CPSC 355: Tutorial 1
Introduction

PhD Student
Fall 2017
Introduction
Joshua Horacsek (PhD Student)
joshua.horacsek@ucalgary.ca
MS 625A
http://cpsc.ucalgary.ca/~joshua.horacsek/
Policy:
- No food or drink
- Be academically honest
- Be respectful of your peers
Connecting the Arm Server
For Linux/macOS users:
ssh arm.cpsc.uclagary.ca -lyour.usernameFor Windows users:
Some Simple Bash
When you log into the ARM server, you'll be presented with a bash (Bourne Again SHell) command prompt. Initially you're in your home directory. Some simple commands are:
- pwd - prints the current working directory
- ls - shows the contents of the current directory
- mkdir - create a new directory
- cd - change directory
- rm - remove file
Bash is actually a scripting language, but you'll only need to know basic commands to get by in this course. See this for more info on bash.
Editing Files
Easy mode:
nano filename.cProductivity mode:
Nano is a barebones text editor, it's great for quick and easy file editing, and has an easier learning curve comapared to emacs.
vim filename.cVi (improved) is a text editor that very heavily relies on text commands. It's a bit of an effort to learn, but improves workflow once you've memorized the key commands.
Vim
By default Vim is in command mode:
- i - changes to insert mode
- w - moves the cursor to the next word
- b - moves the cursor to the previous word
- u - undo
- :w - write the file
- :q - quit
- ZZ save and quit
Cheat sheet: https://vim.rtorr.com/
When you're in insert mode, type as normal, then esc puts you back in command mode
Hello World
#include <stdio.h>
int main(int argc, char *argv[])
{
printf("Hello World!\n");
return 0;
}#include <stdio.h> // Include functions from the standard I/O library
// Define the main function
int main(int argc, char *argv[]) // argc: number of arguments passed
// argv: array to (pointer to) argument text
{
printf("Hello World!\n"); // prints hello world
return 0; // returns 0 (error code 0 = no error)
}To compile, type the following at the bash command prompt:
gcc filename.c -o output_nameI/O Example
#include <stdio.h>
int main(int argc, char *argv[])
{
char name[256];
int age;
printf("Please enter your name:\n");
scanf("%s", name);
printf("Please enter your age: \n");
scanf("%d", &age); // & is the "address of" operator
printf("Hello %s, you are %d years younger than I am\n", name, 27 - age);
}Fix when age < 0, fix when age > 27.
Next time
- Some more functions getchar(), putchar()
- More on c strings (and format strings)
- Pointers, addresses and arrays
CPSC 355: Tutorial 1
By Joshua Horacsek
CPSC 355: Tutorial 1
- 2,117