Oregon State University School of Electrical Engineering and Computer Science CS 261 Recitation 1 Spring 2011
Outline Using Secure Shell Clients GCC Some Examples Intro to C * *
Windows File transfer client: WinSCP Already installed in EECS lab machines Download WinSCP Terminal client for windows: PuTTY Already installed in EECS lab machines Download PuTTY installer * *
Mac SSH built into Terminal Search (Command + F) for Terminal Use a file transfer client such as Cyberduck. Or use scp command. Meet me in my office hours if you don t know scp.
Username: Your alias Password: password Private Key file: Ignore WinSCP
After Login
PuTTY
PuTTY Login as your alias with your password
PuTTY After Login, you will see terminal like the one below
Basic Linux commands pwd Present working directory ls list files and directories in current directory % ls la : el denotes long listing a including all hidden files cd Change directory mkdir make new directory cp copy <srcfilename> <desfilename> mv Moves / renames <srcfilename> <desfilename> rm remove file cat show file content exit exit the session chmod Change permissions * *
Basic Linux Commands Linux has great help man (short manual) command Try man pwd command on your terminal. Similarly try man ls man cd
Basic Linux Commands. (single dot) Represents current directory.. (two dots) Represents parent directory Use Internet to know more about these commands. You will get used to them. More information on how to use gcc and vim editor, please refer to 2010 Fall CS151 * *
Text Editors Use your favourite text editor to write programs. Here are a few recommendations Windows Notepad++ Download Notepad++. Linux Gedit Kate There are lots of other editors You can even use IDEs like Visual Studio or Eclipse If you write programs using these IDEs, make sure your programs work as expected by the homework. You are on your own when it comes to IDE features. * *
Compiler Your program should be compilable by gcc Version: (GCC) 4.4.6 (as available on EECS machines) Run this command to know gcc version gcc - - version Make sure your program compiles/runs on EECS lab machines or flip/flop machines before submitting them. Compilation errors mean Zero marks.
gcc Gnu Compiler Collection Think of compiler as a language translator between you and the computer. Think of Linker as a automobile engineer who assembles different parts to create a vehicle that runs. Individual parts don t run. Even engine cannot run on its own. Compiling with GCC: Output: gcc <list of options> sourcefile.c gcc - o hello.o hello.c Compiling the code converts it into object files (*.o) Linking the code uses the information from the object code to build executable. * *
gcc Gnu compiler Collection Sometimes all you want to see is if your code compiles. On large projects linking object code takes significant time. Just compile Example: gcc c code1.c code2.c code3.c This Code produces three object files: code1.o code2.o code3.o To link the individual.o files to generate the executable: gcc o executable code1.o code2.o code3.o The same can be done in a single step : gcc o executor code1.c code2.c code3.c * *
make (also called Gnu make) Think of make as an organizer Good organizing saves you time Lets you not worry about repeated work make makes your coding life simple by Running all the commands using a simple Makefile Write a makefile and run make You need not spend your time on writing makefile or about make. We will give you makefile. Follow the instructions and run make.
Sample Makefile Lets say you are asked write a program in a file named hello.c Then content of makefile would be: Tabs are very important in make. Don t mess with Tabs. default:main main: hello.c gcc hello.c o hello clean: rm hello hello.o Simply running make runs the section main Because default is main Running make clean runs clean section. * *
The C Programming Language Best way to learn C would be to get a textbook and follow the lecture notes. Any textbook should be fine.
Headers in C Essential header: #include <stdio.h> :Includes the standard Input/ output library. Without this statement the program will not be able to print/read data. Other headers & including any files : (Next class..) * *
Variables & function declaration All the variables/functions are required to be declared prior to its use in the program. int add (int, int); // function declaration /prototyping void main(){ } int var1 = 10; printf( %d, var1); int var2=20; printf( %d, var2); int result = add(var1, var2); int add(int a, int b){ } return (a+b); * *
Coding Guidelines Write comments. Maintain readable indentation. Should be readable by others. Remember that you are writing code which will be evaluated by someone else. Follow the instructor guidelines on naming conventions. For files and functions.
Hello CS 261 /* Filename: hello.c Author: kranti Output: prints a message on the console. */ #include <stdio.h> int main (void) { printf( Hello CS 261!!!!\n ); return 0; } Compile gcc o hello hello.c Runnnn!!!
That s all for today. * *