Running C Programs on Thunder, Astro, or Nimbus 1. Press any key to turn on your computer. a) At the prompts: Login: Password: Type in the login name and press the return key. Type your password given to you by you lab instructor for the Sun workstation and press the return key. This gets you into the Sun computer system console. Now you need to connect to the university computer on which you have your other student account (Nimbus, Astro, or Thunder). Please see lab instructor if you don't have any of those accounts. b) At the Sun computer prompt type in telnet astro (or telnet nimbus or telnet thunder - depending on your UNIX machine): Ex: rsmith@chewbaca:~> telnet astro 2. Log on to astro, thunder, or nimbus as shown below: Login: Password: You will then get the following menu: U N I X M E N U Command Brief Description of the Command ------- -------------------------------- 1 - Use electronic mail (pine program) 2 - Browse the World Wide Web (lynx program) 3 - Access news/discussion groups (tin program) 4 - Explore online information (gopher program) 5 - Exit to the Unix system prompt to run other applications or to log off Press 5 then return to get to the thunder, astro, or nimbus prompt: Ex:[UnixCluster] ^ > 3. To enter your program, type in: Ex:[UnixCluster] ~ > pico first.c which puts you in the pico editor. You will get a blank screen with the cursor at the top and some control options at the bottom. You should type in each line of your program. Press Tab to indent each line. Press return to move cursor to the next line. Hold down the control and x key at same time to exit and save your program under the filename first.c 4. Now it is time to attempt to compile your program. Type in cc first.c Ex:[UnixCluster] ~ > cc first.c 5. If you have any errors, they will be listed on the screen followed by the thunder prompt. Go on to step 6 if you don't have any errors. If you have errors, you must reenter pico first.c to correct the errors in file first.c. Type in the following to get pico back with file first.c loaded in Ex:[UnixCluster] ~ > pico first.c *** Time saving tip -- To move the cursor to the error line (e.g., line 12) in your program type at the UNIX prompt: Ex: [UnixCluster] ~ > pico +12 first.c When you are finished modifying the file, try to recompile it with the C compiler again: Ex:[UnixCluster] ~ > cc first.c 6. If there are no errors, the C compiler will create an object file and link it for you automatically, creating an executable file named a.out. To load and run this file, just type its name after the prompt: Ex:[UnixCluster] ~ > a.out Your program will execute and any prompt messages or output messages will be displayed. You must enter the data requested after each prompt message and press return. 7. Examining your output will tell you whether your program is correct. If it is, you will want to get a listing of your program and your output to hand in to your lab instructor. To do this, follow the steps below. The message below each line explains its purpose - don't type it in!!! a.)[UnixCluster] ~ > script first.doc (opens a script file named first.doc) b.)[UnixCluster] ~ > cat first.c (displays the program first.c to the screen and copies it to first.doc) These lines make a copy of file first.c called first.doc and then use first.doc as a script file. From this point on, each file appearing in the screen is also copied to the script file first.doc. The script file begins with the source program. To append the output to the script file, you must execute it again. c.)[UnixCluster] ~ > a.out This line and the program output appear on the screen an in the script file. If you want to run the program again with different data, just repeat this line. You can run it as many times as you wish and each time the new output appears on the screen and in the script file. d.)[UnixCluster] ~ > exit This command will close the script file. You will get the message: Script done, file is first.doc ***Note. It is very important that you close the script file after you are finished running your program. If you do not, all subsequent interactions between you and the computer will be captured in the script file and will result in a huge mess. If you have found an error and need to edit and correct your program, make sure you close the script file, make corrections to your program, and compile and run it again. When you are sure it is correct, you can redo steps a.) - d.) regarding the script file. At this point you can view the script file first.doc in the pico editor (type in pico first.doc) to make sure it does not contain garbage or you can send the file to the printer. To print from astro, thunder, or nimbus, type at the prompt: or you can send the file to the printer. To print from astro, thunder, or nimbus, type at the prompt: [UnixCluster] ~ > lpr -Pcis2 file.doc To print from your Yoda account type at prompt: Ex:rsmith@chewbaca:~> lpr -Plp2 file.doc 8. When you are all done, you can log out from your UNIX account by typing: Ex:[UnixCluster] ~ > exit **** Also log out from your Yoda account by holding down the 1st mouse button and selecting from menu: Exit FVWM 9. Some useful UNIX commands: cp file1 file2 (copy file1 into a new file called file2) ls (lists files and directories in the current directory) ls -l (long listing of all files and directories) pico file1 (enter the pico editor and load in file1) pine (Pine mail facility) cc file1 (compile file1 using C Compiler) exit (logout from Thunder) mkdir CIS71 (create a directory called CIS71) cd (change to home directory) cd .. (takes you back up a directory) chmod 700 CIS71 (changes the permission for CIS71 to read/write/execute for the user and no permission for group and everyone else) pwd (shows the present working directory) lpq -Pcis2 (checks the print queue for print jobs) Steps to create the file first.c in the CIS71 directory: 1) [UnixCluster] ~ > mkdir CIS71 (creates a directory named CIS71) 2) [UnixCluster] ~ > chmod 700 CIS71 (changes permission of CIS71) 3) [UnixCluster] ~ > cd CIS71 (change to the CIS71 directory) 4) [UnixCluster] ~ > pico first.c (edit file first.c)