Things you need to know to complete hw1 ----------------------------------------- Compiling --------- The basic flow of the UNIX development cycle is as follows: 1.) create a program file (ex: homework1.c) using your favorite text editor 2.) enter C code into the file and save it to disk 3.) COMPILE the program file into an executable program - to do this, we use the 'gcc' program which stands for GNU C Compiler - at a prompt, type: gcc homework1.c -o homework1 - this command takes the file containing C code and outputs a file called 'homework1' which can be executed from your shell 4.) RUN the program - remember your current working directory is probably not in your PATH environment variable, so to run the program you've just created, use a './' string in front of the binary name - ./homework1 - remember '.' means 'current directory' and '/' delimits directories so by typing './homework1' you are instructing the shell to execute a file located in your current directory called 'homework1' 5.) if there are problems, return to step one and go through the steps again. Remember that when you change the contents of your .c file, you need to recompile the file into an executable before the change is reflected in the running program Sample C Code Explained ----------------------- Following is an explaination of each step of the sample C program given in 'hw1': #include - C language itself does not define any functions, only language definition - standard libraries have been written so that programmers do not have to start from scratch every time they write a program - function definitions allow use of functions are in 'header' files, which typically end in .h - #include is a preprocessor step which essentially finds the given file and puts the contents in place of the line "#include " main() { - defines a function called 'main' which takes no arguments '()' - function statments are contained within curly braces {} - by default, OS will first call the main function of a program printf("Hello World\n"); - calling a function, defined in stdio.h, called printf. - passing the printf one parameter within the () - parameter is a 'string' delimited by double quotes - "Hello World\n" contains 12 characters; 10 letters, a space, and a 'newline' which tells the cursor to go to the beginning of the next line - semlicolon must be placed after all program statments } - ends definition of the main function