DOC PREVIEW
UNM CS 241L - CS 241 Lecture Notes

This preview shows page 1-2-3-4-5-6 out of 18 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 18 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 18 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 18 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 18 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 18 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 18 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 18 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

12/14/2012CS 241 Data Organization using CHello World – in LinuxInstructor: Joel Castellanose-mail: [email protected]: http://cs.unm.edu/~joel/Office: Farris Engineering Center 319% gcc helloWorld.cRead: Kernighan & Ritchie Due Thursday, Jan 191.1: Getting Started1.2: Variables and Arithmetic Expressions1.3: The For Statement1.4: Symbolic Constants22Hello World: A Program in C3{ } Curly Brackets are used to group lines of code into blocks. Lines 3 through 6 make the body of “main”.( ) Parenthesis are used for function parameters. In line 2, the parameter list for “main” is “void”.Step 1A: Secure Shell to *.cs.unm.edu4 PuTTY: free implementation of Telnet and SSH(Secure Shell network protocol) for Windows 95, 98, ME, NT, 2000, XP and Vista on Intel x86 platforms. Mac OS X comes with its own implementation of OpenSSH, so you don't need to install third-party software. From Macintosh HD and go to the Applications folder, then Utilities from within that, select Terminal. moons.cs.unm.edu shuttle.cs.unm.edu3Step 1B: PuTTY: Set Host & Protocol Open Putty5Host:moons.cs.unm.eduortrucks.cs.unm.eduSometimes, one of the servers is down. If one of these does not work, then try the other.SSHStep 1C: PuTTY: Set Window Options6May want to increase Rows from the default 24.When Window is resized: Change the number of rows and columns.Lines of scrollback4Step 1D: PuTTY: Set Translation7Window → Translation → Received data assumed to be in which character set → UTF-8The Linux Host sends a binary single to PuTTY.PuTTY needs to be told which standard to use to translate that signal.Most standards use the same codes for the upper and lower case 26 letters of the 26 English alphabet.“Special” characters, , ©, ±, ñOften have different codes in different standards.Good: hello.c:24: error: ‘i’ undeclared Bad: hello.c:24: error: âiâ undeclared Step 1E: PuTTY: Save Configuration8Give your configuration a name and click Save.You can also customize other parts of the configuration:■ Default User Name, ■ Font Size, ■ Foreground Color, ■ Background Color,■ etc.5Step 1F: Open the Connection9Command PromptMachine NameUser namebash Shell: Default Linux sell environment on cs machinesAside: Unix Shells A Unix shell is a command-line interpreter that provides a traditional user interface for the Unix operating system and for Unix-like systems (i.e. Linux).  The most influential Unix shells: C shell (syntax modeled after the C programming language) Bourne shell early de facto standard bash (Bourne-Again SHell): Superset of Bourne Shell functionality. Default interactive shell for users on most GNU/Linux and Mac OS X systems.106Aside: Poking Around Your Home Directory11pwd: Linux command that returns the absolute path of the current directory.ls: Linux command that lists all files in the current directory.ls -F: The ‘–F’ is a command line option that tells ls to append a ‘/’ character to the end of directories, a ‘*’ character to the end of executable files and an ‘@’ character to the end of symbolic links.Step 2: Create a Working Directory12mkdir name: Linux command that creates a directory with the given name.Returns and error message if a file already exits with that name.cd name: Linux command that looks in the current directory for a directory of the given name. If the given directory is found, then the current directory is changed the given directory.If the cd command is used without specifying a name, then the current directory is changed to the user’s home directory.7Step 3: Open a Text Editor: vim13hello.c: File name passed to vim.If this file does not exist in the current directory, then a new empty file is created with the given name.C source code should be given a file name that ends with .c.vim: text editor.Aside: vim and an Empty File14file nameLine number of cursorColumn number of cursorBefore you can start typing code into vim, you must enter the vim insert command: iblue ‘~’ characters indicate that this space is beyond the end of the file.815Aside: vim Text Editor vim is modal — a design choice that tends to confuse new users unaware of insert-mode. Run in remote graphics window. Run in remote text-only window. Free, and open source – compiled executables for ***every *** platform: Atari 800 Small hardware devices. Very small and simple executable. Tons of documentation Official Website: http://www.vim.org/Tip: if network is problematic, download vim and run locally.Then SFTP.Aside: vim: 1 of 316i Enter insert modev Enter visual select mode (Use normal movement keys)<Esc> Exit current mode (insert or select)y Yank selected textd Delete selected text (when in visual select mode)dd Delete linex Delete characterrc Replace one character with cp (P) Put yanked or deleted text after (before) the cursor.:w Write file:q Quit:q! Quit without saving9Aside: vim: 2 of 3 17←↑→↓ Moves curser left, up, right or down.hjlk Moves curser left, up, right or down.$ or <end> Moves to next ‘\n’ character – Very useful in long (multi-line) lines: In VIM, you cannot just click the mouse in the text to move the curser.0 Moves curser to beginning of line.u Undo last action. Can be stepped backward.U Undo all changes to lineJ Join next line to end of current line.a Append (enter insert mode, after the cursor).Aside: vim: 3 of 3 18:= Display current line number.:n Jump to line number n./x Search for x, where x is a character string./ Repeat last search.:set nu Display line numbers.:set nonu Turn off display line numbers.% Jump to a matching opening or closing parenthesis, square bracket or a curly brace: ([{}])Jump to start or end of a C-style comment: /* */.10Step 4: Enter C Source Code19i (turn on INSERT mode)<enter code>Notice the colors.vim is aware of C syntax.cursorWhen the cursor is on a bracket or parenthesis, vim automatically highlights its match.Turn this off: set noshowmatchSteps 5, 6 & 7: Exit vim, Compile & Run20Within vim:i (turn INSERT mode)<enter code>esc (exit INSERT mode):w (save file):q (quit vim and return to Linux command line)gcc: Runs a C compiler program with the source file hello.c as input.If gcc compiles hello.c without errors, then gcc will produce a.out: an executable file containing machine code../a.out: runs the program../ tells Linux to look in the current directory for a.out.11Syntax Error21oberon 72 % gcc hello.chello.c: In


View Full Document

UNM CS 241L - CS 241 Lecture Notes

Download CS 241 Lecture Notes
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view CS 241 Lecture Notes and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view CS 241 Lecture Notes 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?