0% found this document useful (0 votes)
9 views4 pages

Lab 0

This document outlines the objectives and steps for Lab 0 of CSCI 112, focusing on logging into a server, using a text editor, and writing a simple C program. It provides detailed instructions for setting up the environment, creating and compiling a C file, and submitting the assignment. The lab is due on January 14, 2019, and emphasizes individual completion and adherence to submission guidelines.

Uploaded by

blakestanger
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views4 pages

Lab 0

This document outlines the objectives and steps for Lab 0 of CSCI 112, focusing on logging into a server, using a text editor, and writing a simple C program. It provides detailed instructions for setting up the environment, creating and compiling a C file, and submitting the assignment. The lab is due on January 14, 2019, and emphasizes individual completion and adherence to submission guidelines.

Uploaded by

blakestanger
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Lab 0

Introduction to C
CSCI 112, Fall 2018

Objectives
• Login to your account on csci112.cs.montana.edu.
• Familiarize yourself with an editor such as nano, emacs or vim. (I will use vim.)
Familiarize yourself with basic Linux commands cd, mkdir, ls, pwd, and more.
• Reproduce the source code provided for you below using one of these editors.
• Use gcc to compile your program. Run your first C program.
• Transfer the code to your PC and put in the lab0 assignment folder on
brightspace.

Part One: Setup


1. If on Windows, open the program PuTTY. If on OSX or Linux, open Terminal.
2. Use this as the host name: csci112.cs.montana.edu and use your netid/password
to log in.
3. When prompted, enter your password.

PROTIP: Your password will not show up while typing it.

4. Use the mkdir (make directory) command to create a new directory to use for
this class.
$ mkdir lab0
5. Change into that directory using the cd (change directory) command.
$ cd lab0
6. Check the current path using the pwd (print working directory) command.
$ pwd
/home/<netid>/lab0
7. Select a unix text editor to use. There are several choices:

$ nano (for the nano editor)


$ emacs (for the emacs editor)
$ vim (for the vim editor)

PROTIP: Nano is easy to use and appropriate for first-time unix users. Emacs and vim
have a steeper learning curve but provide nice features for programming. vim is what
most people use at their jobs.

Part Two: Your First C Program


1. Create a new C file named lab0.c. For example, using the vim editor, execute:
$ vim lab0.c
2. Retype the code given in Figure 1 into your C file.

#include <stdio.h>

/* <put your name>


* Lab 0, CSCI 112
* <current date>
*/

int main(void) {
// prints “Hello World”
printf(“Hello World\n”);
// exit with no errors
return(0);
}

Figure 1: “Hello World" Program

PROTIP: Be sure to include the comments as explainable, readable, intelligent


comments as well as a clean, readable formatting of your code account for 20% of your
grade.

PROTIP: The control character `\n' means newline.

PROTIP: The caret symbol ^ means use the CTRL key.

3. Save your work and exit the editor. For example, in vim type ZZ (or shift zz).
4. Verify your file exists on disk using the ls (list) command.
$ ls
you should see lab0.c
5. Verify your file is not blank by printing it to the terminal using the more command.
$ more lab0.c
Your file should then print to the terminal.

PROTIP: Start typing your file name and use the TAB key to autocomplete.

6. Compile your program using the gcc compiler.


$ gcc –o lab0 -Wall lab0.c
7. Perform another ls command and verify you created an object .o file and your
executable (called lab0).
$ ls
lab0.c lab0
8. Run your executable program from the command line as follows:
$ ./program0
You should see Hello World displayed on the console.

PROTIP: One dot . refers to the current working directory and two dots .. refers to the
parent directory. The command $ cd .. navigates to the parent directory.

9. Take a screen shot of the compile and run commands showing that your program
printed Hello World

Congratulations, you just successfully wrote and ran your first C program!

Submission
• Lab Day: None for this one
• Due Date: Monday, 1/14, at 5pm

1. Logout of your connection to the server using the exit command.


$ exit
2. You now must retrieve the file from csci112.cs.montana.edu.
• If using Windows, open an FTP client, such as WinSCP, locate your file, and
download it to your local machine.
• If on OSX or Linux use the scp (secure copy) command.
$ scp <your_netid>@csci112.cs.montana.edu:lab0/lab0.c .

PROTIP: Submit only your C file to D2L. Do not submit your object file or
your executable program. Do not archive (e.g., zip) your file.

3. Submit both your .c file and your screenshot to brightspace.

Each student will complete and submit this assignment individually. Submit your work
on or before the deadline as late work will receive a 50% penalty. Labs submitted more
than 24 hours late will not be accepted.

Your code must match the code in this document.

You might also like