Compiling a C Program. Before we can begin we must open a telnet session to phobos. There are a...

12
Compiling a C Compiling a C Program Program

Transcript of Compiling a C Program. Before we can begin we must open a telnet session to phobos. There are a...

Page 1: Compiling a C Program. Before we can begin we must open a telnet session to phobos. There are a number of ways to do this, but the easiest is to click.

Compiling a C ProgramCompiling a C Program

Page 2: Compiling a C Program. Before we can begin we must open a telnet session to phobos. There are a number of ways to do this, but the easiest is to click.

Before we can begin we must open a telnet session tophobos. There are a number of ways to do this, butthe easiest is to click on Start, then Run, and thentype the word telnet and press the Enter key.

Page 3: Compiling a C Program. Before we can begin we must open a telnet session to phobos. There are a number of ways to do this, but the easiest is to click.

A window will open on your desktop. This is what it lookslike using Win2000. Type open phobos.senecac.on.caand then press the Enter key. The Win98/95 method is next.

Page 4: Compiling a C Program. Before we can begin we must open a telnet session to phobos. There are a number of ways to do this, but the easiest is to click.

When the telnet window opens in Win98/95, click on Connect and then Remote System.

Page 5: Compiling a C Program. Before we can begin we must open a telnet session to phobos. There are a number of ways to do this, but the easiest is to click.

Type phobos.senecac.on.ca in the Text Box labeledHost Name, then click on Connect.

Page 6: Compiling a C Program. Before we can begin we must open a telnet session to phobos. There are a number of ways to do this, but the easiest is to click.

The procedure is the same from this point using eitherWin2000 or Win98/95. Enter your user name and thenpress Enter, and then enter your password and pressEnter.

Page 7: Compiling a C Program. Before we can begin we must open a telnet session to phobos. There are a number of ways to do this, but the easiest is to click.

Once you have logged on to the system your cursor will be at the command prompt ($). We are going to use a program named nled to create our C source file. Type nled welcome.c at the command prompt and then press Enter.

Page 8: Compiling a C Program. Before we can begin we must open a telnet session to phobos. There are a number of ways to do this, but the easiest is to click.

The nled edit window opens in insertion mode. We can just start typing to enter text. Type the code for the C source file and then press the Escape key (Esc) and the x key at the same time to save your file and exit nled.

Page 9: Compiling a C Program. Before we can begin we must open a telnet session to phobos. There are a number of ways to do this, but the easiest is to click.

Your cursor will be back at the command prompt after nled closes. Type cc welcome.c and press Enter. phobos will pause for a moment while your file is compiled. When it is finished the command prompt will reappear. Type a.out to see the output of your C program.

Page 10: Compiling a C Program. Before we can begin we must open a telnet session to phobos. There are a number of ways to do this, but the easiest is to click.

What Happened?

Our source code is a series of instructions that we want to have carried out. Our instructions must be translated in to a language that can be understood by a computer. When we type cc filename.c we are telling the computer we are using to compile our source file, using the C compiler, into an executable file that can be run to produce the desired result. Remember that when we are logged on to phobos using a telnet session that the source file and executable file reside on phobos. The executable file will only work on phobos. To create an executable file that will work on your local machine the source file would have to be compiled locally.

Page 11: Compiling a C Program. Before we can begin we must open a telnet session to phobos. There are a number of ways to do this, but the easiest is to click.

What Happened?

The default name for an executable file on phobos is a.out. To give your C program another name you must tell the compiler at compile time. If we wanted to name our executable to be named welcome1 the command would be:

cc welcome.c -o welcome1

The general format of the compile command is:

cc source.c - produces a.out

cc source.c -o outputname - produces outputname

Page 12: Compiling a C Program. Before we can begin we must open a telnet session to phobos. There are a number of ways to do this, but the easiest is to click.

Summary

•Open a telnet session to phobos

•Use nled to create a C source file

•Use the cc command to create an executable file

•The default name for the executable file on phobos is a.out

•Run the executable file by typing its name at the command prompt