MAE2360 001 Lecture 1
MAE2360 001 Lecture 1
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:
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
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.
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
1. Structured programming
2. High portability
4. Free format
5. Collection of functions
7. A statement "#include < stdio.h > " must be placed before the main function.
8. etc...
C FORTRAN
Modern Archaic
Structured Spaghetti
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
$ 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).
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 syntax
• 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.
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.
$ nano hello.c
(create/edit file)
$ gcc hello.c
$ 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).