Sie sind auf Seite 1von 10

Project 1: Getting Started

Due: 2011/01/26 11:59 PM

CS 1313

1. Objectives
Log in to ssh.ou.edu. Use Unix commands: cd, chmod, cp, exit, gcc, ls, mkdir, nano, source. Type in, compile, and run a C program. Submit source code to D2L.

In this case, we'll actually go through them in order.

2. Grading
We'll explain more in lecture and in lab about what this means, but here's the grading summary for this project: Milestones 20% Ask the user for their age. 25% Input the age from the user. 25% Tell the user their age back again. 15% Return EXIT_SUCCESS to the operating system. 10% Documentation. 5% Formatting. Penalties -100% More than one day late (except for byes, as explained in the syllabus). -50% Compiling fails. -20% One day late. -20% Resubmission for uploading the wrong file or failing to upload correctly. Each project has different milestones contributing to the grade. You can get partial credit for partially completed milestones. Across projects, we will keep consistent the contributions due to documentation, formatting, compiling, late submissions, and correcting wrong submissions. For project 1, we actually give you the entire program, so if you follow instructions correctly, you should get full credit. If those penalties seem harsh, just learn to get it right. Make sure you test your programs, and make sure you upload the right file on time. On the plus side, you can't get a negative grade on a project. Doesn't that give you warm fuzzies?

3. Log in to ssh.ou.edu
In this course, you won't be running your C programs on your own computer. Well, you can do that if you want, but you also need to run them on a common Unix (well, Linux) platform that we'll all be sharing. We'll pretend to connect to a computer called ssh.ou.edu, but that's really a faade that redirects you to either kennedy.itsc.ou.edu or polk.itsc.ou.edu or maybe others. To run programs on these computers, you need a tool supporting SSH (secure shell) to connect to ssh.ou.edu. On Mac or Linux, you first bring up a terminal to use ssh. On Windows, you need a separate tool, such as PuTTY (http://www.chiark.greenend.org.uk/~sgtatham/putty/). It is already installed on the lab computers, but you if you want it on your own computer, you will likely need to install it yourself. Page 1 of 10

For both PuTTY and FileZilla, you'll log in to ssh.ou.edu with your 4x4 and corresponding password, the same as for oZONE or D2L.

SSH (using PuTTY) on Windows


When you launch PuTTY, it gives you a dialog window for connection and configuration. Enter ssh.ou.edu for the Host Name, and make sure the SSH option is selected. To save these settings for future use, enter a name for the session (such as ssh.ou.edu) under Saved Sessions then click Save.

Later, when you launch PuTTY again, you can click on the ssh.ou.edu session, and click Load. That way, you don't need to type it in or reconfigure it again. Once you have the session information loaded (as seen under Host Name), click Open to connect to the remote computer. The first time you SSH to a remote machine, it asks you if you trust that computer. There's no convenient way to prove that the remote host is really what it claims it is. But once you have its fingerprint stored on your machine, you'll be warned if it ever changes. If it does, that might be a sign that someone is intercepting the network communication. So, when PuTTY asks you about saving the information, say yes. (Sadly, for campus Windows machines, saved application settings are lost whenever you log out. But saving settings could be useful on your own computer.)

Page 2 of 10

Once you decide to trust the connection, you can log in with your 4x4 and password.

SSH on Mac
As mentioned earlier, to use SSH on a Mac, you first need to bring up a terminal. You do this with the Terminal application. It is usually found in Finder under Applications > Utilities. Once you have a terminal Window, enter the following command and then follow instructions: $ ssh <your4x4>@ssh.ou.edu The first time you connect, you will likely be asked about whether you trust the remote machine, just as for PuTTY on Windows. To connect, you have to answer yes. See the discussion above for more info.

4. Use Unix commands


Actually, when we say Unix in CS 1313, we are using the Linux operating system. Macs are Unix-based, too. Look up Unix at Wikipedia or somewhere if you want to figure it all out. Anyway, using Linux is like using Page 3 of 10

Windows or a Macintosh, except Linux is free. When you use a Linux computer, it normally looks and acts a lot like using Windows. However, in CS 1313, we won't be using Linux normally. We'll be using a command line interface, which we'll also call the shell. Using text commands at a command line has pros and cons vs. using a graphical interface. When typing commands from here, make sure to include spaces between other symbols or letters exactly when shown.

First time only!


These are instruction to help you set some things up for your account. You only need to follow these steps once during the semester. Use PuTTY or ssh to connect to ssh.ou.edu, as discussed earlier. Once you are in, enter the following commands to copy some configuration files to your account. Don't miss that trailing dot (.) after the last space! At a Unix shell, you are always in some active folder (a place where files can be saved), and . means the one you are currently in. -bash-3.2$ cp ~palm5988/.student/.nanorc . -bash-3.2$ cp ~palm5988/.student/.profile . The first one file above configures the nano text editor, and the second configures primary account settings. Specifically, it changes your shell prompt and the permissions on the files you create. The prompt is what it says to the left of your command entry. The permission settings make it so only you (and superusers such as some OU IT staff) can see the files you create after the configuration change takes effect. Before those account configuration settings take effect, you need to log back in from scratch. To make them take effect now, you need to run another command: -bash-3.2$ source .profile palm5988@kennedy:~$ Note that my prompt changed (from -bash-3.2$ to palm5988@kennedy:~$). This shows my username (palm5988), the computer I'm logged into (kennedy), and the folder I'm in (~, meaning my home folder corresponding to the H: drive on campus Windows computers). Folders (where you keep files) are also called directories. Make a directory for CS 1313, where you will store all your project directories and files: palm5988@kennedy:~$ mkdir cs1313 Now list the contents of your current directory (and those are lowercase Ls in the command, not number 1s): palm5988@kennedy:~$ ls -l total 112 drwx------ 3 palm5988 faculty 4096 Jan 18 09:45 cs1313 drwx------ 7 palm5988 faculty 4096 Jan 18 09:44 Other -rw------- 1 palm5988 faculty 87040 Oct 30 2009 Thumbs.db You may have multiple files or directories, but among the listing you should see cs1313, along with letters drwx------ at the beginning of the line it is on. That means it is a directory and among ordinary users, only you have permissions (read, write, and execute, specifically). If other users have access, you will see more cases of r, w, and/or x in the place of some of the dashes.

Page 4 of 10

You can stay logged in to complete project 1, but whenever you want to log out, just enter: palm5988@kennedy:~$ exit When using PuTTY, the window closes when you are logged out. When using a Mac terminal, you still need to exit that as well if you have nothing else to do there. The key combination Ctrl+D also works to exit a session. Now for the project.

5. Type in, compile, and run a C program


Log in to ssh.ou.edu (using PuTTY or ssh), if you aren't already logged in. We'll actually continue to run Unix commands here, even thought we're not under that section heading anymore. Sorry. Go to your cs1313 directory with the change directory command: palm5988@polk:~$ cd cs1313 palm5988@polk:~/cs1313$ Now make a new directory just for project 1 and go into it: palm5988@polk:~/cs1313$ mkdir project1 palm5988@polk:~/cs1313$ cd project1 palm5988@polk:~/cs1313/project1$ Then use nano (a "text editor") to create and write your first program: palm5988@polk:~/cs1313/project1$ nano person.c Type in the following program. (Don't copy and paste it.) Your TA will show how to use nano. Ask for more help if you need it. Don't worry about the colors of the text. What matters are letters, numbers, symbols, and even white space to some extent: /* CS 1313 Project 1: Getting Started Author: <Your name goes here!> */ #include <stdio.h> /* for printf, scanf */ #include <stdlib.h> /* for EXIT_SUCCESS */ /** * The program starts here. * * Ask the use for their age then repeat it back to them. */ int main(void) { /* Integer variable for age. */ int age; /* Ask the age. */ printf("Hello! How old are you? "); scanf("%d", &age);

Page 5 of 10

/* Tell it back. */ printf("%d years! Wow, that's old!\n", age); /* No errors happened that we noticed. */ return EXIT_SUCCESS; } You can save your file by Ctrl+O then Enter (if you don't want to change the name). Quit nano by Ctrl+X and following instructions. To compile programs, we will be using the GNU C compiler. However, using it is a bit tricky. You have to tell it the name of the program you want to create (output), and it's easy to make mistakes doing that. So let's make a "shell script" to run gcc for us. Use nano to create a new file called "build": palm5988@polk:~/cs1313/project1$ nano build Enter the following contents, then save and exit (quit) nano. gcc -o person person.c Then you can "change the mode" of your build script to let you (the owning user) run (or execute) it as a command. The chmod command can also be used for changing file access permissions. palm5988@polk:~/cs1313/project1$ chmod u+x build Now run your build script and list your directory contents afterward. You have to put "./" first to run commands in the current directory: palm5988@polk:~/cs1313/project1$ ./build palm5988@polk:~/cs1313/project1$ ls -l total 28 -rwx------ 1 palm5988 faculty 22 Jan 17 17:01 build -rwx------ 1 palm5988 faculty 4905 Jan 18 15:06 person -rw------- 1 palm5988 faculty 561 Jan 18 15:05 person.c Now, run your person program (if you had no errors building it), entering whatever age you want: palm5988@polk:~/cs1313/project1$ ./person How old are you? 42 42 years! Wow, that's old! That's what success looks like for this project. You've written and run programs in two different languages (C and shell)! You can exit from the remote computer when you are done.

6. Submit source code to D2L


You need to do this for each project, but we'll only draw extra attention to it in the first project. To upload your file, you need to log into D2L (https://learn.ou.edu/) then click the link for your Friday lab section. In case you forgot your section number, here's a handy table: Section Label Lab Time Page 6 of 10

C S-1313-011 C S-1313-012 C S-1313-013 C S-1313-014

10:30-11:20 12:00-12:50 1:00-1:50 2:00-2:50

Or as another hint, it's not the one labeled 010. That's the main lecture section. You'll find quizzes there, and your grades will be there, too, but there'll be no place to submit projects at section 010! Once you get to your lab section site, click the link Dropbox, then choose the correct dropbox for the project. That means Project 1 this time.

When the project folder comes up, click Add a File then choose a file from your computer.

The program you need to upload for each project is your .c file! Here, that's specifically person.c. Don't upload the .c~ file nor the person executable. For some projects, you might have other files you also need to upload. If you upload the wrong file, and need to correct it after the due date, talk to your grader. The standard penalty (as mentioned earlier) is -20% to resubmit the correct file later!

Page 7 of 10

The files and folders (i.e., directories) at ssh.ou.edu are the same ones that Windows computers on campus see under the mapped H: drive. You can access them directly as if they were on the Windows computer itself.

If you have the file available from your computer, you can choose it and then upload it in your browser to D2L.

After this, you still aren't done yet! If you stop here and wait until you are late, talk to your grader and expect -20% for failing to upload correctly. D2L requires you still to click the Submit button after uploading.

Page 8 of 10

Follow all the steps, and make sure you get an email confirming your submission! If you don't get an email, either you have your email address misconfigured (and you'll miss other important info) or you didn't submit your project!

Copying files with FileZilla


If you aren't on a standard campus computer with H: access, you need a special tool to transfer files. For either Windows or Mac, a good option is FileZilla (http://filezilla-project.org/). For your own computer, you will also need to install this yourself. Using FileZilla, you can copy files to and from your own computer. Once they are on your own hard drive, then you can upload them to D2L. To connect with FileZilla, click the Site Manager button at the left of the tool bar, then the New Site button. Pick a name such as ssh.ou.edu then enter ssh.ou.edu in the Host field. Change Servertype to SFTP SSH File Transfer Protocol and Logontype to Ask for password. Enter your 4x4 in the User field, then click Connect. (In the future, the ssh.ou.edu site should be available in the drop down at the left of the tool bar.)

Page 9 of 10

You'll need to enter your password, and you'll also need to establish that you trust the remote computer, just as you did for PuTTY or ssh. Click the checkbox to always trust this host, as discussed earlier for PuTTY.

Once you are logged in, you can navigate to your project1 folder and copy the person.c file to your own hard drive. On one side are your local files, and on the other side are the remote files. You can drag and drop files from one side to the other. You can safely ignore most other details in this window.

Once the file is on your own hard drive, you can submit it to D2L using your web browser.

7. That's all, folks!

Page 10 of 10

Das könnte Ihnen auch gefallen