This lab will introduce you to command line interaction, text editing, and the C compiler.
This page will be available as
http://www.tricity.wsu.edu/~bobl/cpts121/lab01_basic_tools/writeup.html
Calling it up in a browser will allow you to access URLs.
You may use any Windows text editor you like for this class, but sooner or later you should learn one of the standard one for programmers: either vim or emacs. You can start a tutorial for vim in a MinGW terminal emulator window by entering:
$ vimtutor
(Leave off the "$ " when you type. It's there to indicate that it's a shell command.) There is also a good on-line tutorial on vim at:
http://www.openvim.com/tutorial.html
Run either of these to get started with vim.
Remember that tutorials are like piano exercises: If you want to get good at the subject, you should go through them more than once.
There are many more commands in vim than are covered in either tutorial. Knowing how to use them can make you a more productive programmer. You may want to keep a reference card handy. A good one is at:
http://michaelgoerz.net/refcards/vimqrc.pdf
Remember to exit vim and return to the command line with ESC (if you're in insert mode), followed by wq{RETURN}.
Start a MinGW terminal emulator window.
Plug your thumb drive into the USB port on the front of your workstation.
Give the system a few seconds to recognize it as, we'll assume, the I: drive.
Move your working directory to the I: drive:
$ i:
Create a directory for this course:
$ mkdir cpts121
Change your current directory to that directory:
$ cd cpts121
Create a directory for this lab:
$ mkdir lab01
Change your current directory to that directory:
$ cd lab01
Start up vim on a new file named first.txt:
$ vim first.txt
Use the editor to put something unique in this file such as your name and address, a joke, or a favorite saying. You'll show it to the lab assistant to indicate completion of this part of the lab.
All the files you create will now be saved to this directory (d:\cpts121\lab01) by default. From now on, put each lab assignment in its own appropriately-named directory.
In your lab directory, use vim to create a file named hello.c with these contents:
#include <stdio.h> int main(void) { printf("Hello, world!\n"); return 0; }
(You'll want to commit this program to memory. It's a classic.)
Then exit to the command line.
Compile hello.c into an executable hello as follows:
$ cc -Wall hello.c -o hello
Run hello and see the results:
$ ./hello Hello, world!
Copy hello.c to a different file hello_me:
$ cp hello.c hello_me.c
Using vim, modify hello_me.c to print your name instead of "world".
Compile hello_me.c to an executable hello_me.
Verify that the program now does what you want it to.
Use the ls command to see all the files in your working directory. You should know what each name means.
The lab assistant will check your hello and hello_me files.
Write a program ball_drop.c that prompts the user for a number of seconds and then compute and print how far a ball released at sea level will fall (in the absence of air resistance) in that many seconds using the formula
where g is 9.8 meters per second per second at sea level. Use this template:
#include <stdio.h> int main(void) { // replace this comment with code to // 1. declare and initialize variables // 2. prompt the user to enter a time // 3. read the time with "scanf()" // 4. compute the result // 5. print the result with "printf()" return 0; }
and, for an extra challenge, print the result with only one decimal place.