#01 (01/17/2024)

How to access UTA computer resources

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:
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

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

Skeleton C programs

int main()
{
return 0;
}
#include <stdio.h>
int main()
{
printf("Hello world\n");
return 0;
}
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).




File translated from TEX by TTH, version 4.03.
On 27 Jan 2024, 22:31.