0% found this document useful (0 votes)
18 views8 pages

MAE2360 001 Lecture 1

The document provides instructions for accessing UTA computer resources, including commands for Windows and Mac users to connect via SSH. It outlines steps to run a C program on the server, including using text editors and compiling code. Additionally, it compares C programming with FORTRAN and lists essential Unix commands and C syntax rules.

Uploaded by

owenramos777
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views8 pages

MAE2360 001 Lecture 1

The document provides instructions for accessing UTA computer resources, including commands for Windows and Mac users to connect via SSH. It outlines steps to run a C program on the server, including using text editors and compiling code. Additionally, it compares C programming with FORTRAN and lists essential Unix commands and C syntax rules.

Uploaded by

owenramos777
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

How to access UTA computer resources

If you are on campus, you can enter the following commands. If you are off campus, you must
use Pulse Secure VPN first.

• Windows users:

o Enter ssh [email protected] in the search box where abc1234 is to be


replaced by your NetID.
or

o putty (small remote access client)

• Mac users: Terminal app -> omega.uta.edu

All CUI (character based user interface), not GUI.

Unix Command summary

How to run a C program ?

1. Login to omega.uta.edu via DOS or putty.

2. $ nano -z myprogram.c

"$" is the system prompt so do not type it. The "-z" is to enable control-z (temporarily exiting from
nano - optional).

3. Save the file (Control-O) and Control-Z to temporarily exit from nano.

4. $ gcc myprogram.c

5. $ a.out
6. If there is a syntax error, go back to item 2 by issuing fg and re-edit the file.
$ fg

7. If there is no syntax error, run the executable file.


$ a.out

8. To quit from omega.uta.edu, enter exit, logoff or hit control-D.

Editors

Unlike MSWord, there is no visual text editor available in terminal mode. Some of available editors
installed on many Unix system include:

• nano

• emacs

• vi

vi is the oldest text editor on Unix but if you come from MS Word, you may feel that its command
sequence is cryptic. nano is more intuitive and emacs is the most comprehensive text editor on
Unix. No matter, the best way to learn an editor (or programming for that matter) is to use it.

The following is a comparison table:

Program nano emacs vi

Save and exit ∧x ∧x∧s esc :wq!

Delete line ∧k ∧k dd

Delete char ∧d ∧d x

Prev line ∧p ∧p k

Next line ∧n ∧n j

Next char → ∧f l

Prev char ← ∧b h

Next screen ∧v control-F

Prev screen esc v control-B

• nano command list

Characteristics of the C programming language

1. Structured programming
2. High portability

3. Precise manipulation of hardware

4. Free format

5. Collection of functions

6. Flexible data structures

Some peculiarities about the C programming language

This is a partial list of what C stand out.

1. A statement must end with ";" (semicolon).

2. A program is a set of functions each of which returns a value.

3. A function must have an argument even though it's empty (void).

4. A comment must start with /* and end with */.

5. All the variables must be declared first.

6. The function, main(), is the first program to be executed.

7. A statement "#include < stdio.h > " must be placed before the main function.

8. etc...

Comparison between C and FORTRAN

C FORTRAN

Modern Archaic

Structured Spaghetti

System programming Scientific programming

Moderate library Huge legacy library

Function call by values Function call by reference

Unix command primer

Essential commands in Unix

1. ∧f (forward) ∧b (backward) ∧d (delete) ∧k (kill) ∧p (previous) ∧n (next) ∧a (top of line) ∧e (end


of line)

2. ∧z (exit to command line temporarily)


$ fg (to back to nano (or emacs))
3. $ gcc program.c ; a.out

4. $ rm myfile.c
(delete file)

Once deleted, the file cannot be restored. You can delete multiple files using a wild card (*) as

$ rm myfile.*

If you want to delete all the files in your directory (but you know the consequences), issue

$ rm *.*

5. $ ls

You can add an option to control the output. For example, to get more information for individual
files, issue

$ ls -lg

6. $ mv oldname.c newname.c

7. $ cp original.c new.c

8. $ cat program.c (content)

$ more program.c

9. $ exit
$ logout
$ ∧d

10. To copy your C program to a PC application: Highlight the range and right click the toolbar,
Edit, Copy, then control-V (paste).

Command line editor and nano (or emacs)

The following is common for both nano (and emacs) and the command line editor. By using the
following shortcuts, you can navigate on the screen quickly.

C-a Top of line "a" for first alphabet

C-e End of line "e" for end

C-f Forward by one character "f" for forward

C-b Backward by one character "b" for backward

C-d Delete character on cursor "d" for delete

C-k Delete to end of line "k" for kill


C-p Previous line "p" for previous

C-n Next line "n" for next

C syntax

• A C program is a set of functions.

• A function is a code to return a value upon exit where the returned value must be one of
the int (integer), float (floating, real numbers), double (double precision real numbers)
or char (a character, a special case of integer) types.

• The syntax of a function is

type name(type argument)

statement1;

statement2;

.........;

.........;

/*

comment1

comment2

*/

some_function(some_argument);

return value;

}
Example:

int main()

float a;

if (a>0) printf("Hello\n");

return 0;

• A special function main is the one to be executed first. ANSI recommends that
the main function is of integer type and returns 0 value upon exit.

• If a function is called (used) within another function, that called function must be defined
elsewhere.

Skeleton C programs

int main()

return 0;

#include <stdio.h>

int main()

printf("Hello world\n");

return 0;

• The program above prints a string "Hello world" followed by a new line (\n).

• Since it uses a function, printf, that function must be defined somewhere. The first line
calls a file, stdio.h, which is stored in the system file area. Most of the basic I/O functions
are located in stdio.h.

• Here is a link to the list of functions defined in the ANSI standard C library.

• The first line #include is called a preprocessor directive, not part of the C program.

• \n is a special character that represents the next line.


• A function must have a type of the value it returns such as int, float, double etc...

You can execute this program by

$ nano hello.c

(create/edit file)

^Z to temporarily exit from nano (emacs) to command line

$ gcc hello.c

if it is not compiled, go back to nano (Emacs) by

$ fg

otherwise

$ a.out

Hello world

The program gcc on omega.uta.edu compiles the source file, hello.c, and creates an executable
file a.out (this is the default name).

You might also like