C Commands (: Fortran Commands)
/* ..... comments ...... */
Preprocessors
#include filename : #include < stdio.h>, #include "mylib.h"
#define name[(parameters)] value-expression : PRAMETER
#undef name
if condition
..... statement ..... ;
#elif condition
..... statement ..... ;
#else
..... statement ..... ;
#endif
#ifdef name : if name is defined
..... statement ..... ;
#ifndef name : if name is not defined
..... statement ..... ;
Declaration of subroutine-function name (except int or void type)
type sub1 (par1, par2)
type sub2 (par.......)
type sub3 (par.......)
Declaration of Grobal variables : COMMON Block
Integer : short, int, long, unsigned short, unsigned, unsigned long
Real : float, double, long double
Character : char, unsigned char, signed char
Enumerated : enum
enum tagname {elemnt1, elemnt2, ....., elemntn} variablelist
Pointer : * &
*p : p is pointer variable (value stored in address p)
&var : pointer (address) of var
Character string name or Array name is a pointer : do not use &
Structured : struct strctname {item1; item2; ..... itemn;} strctdatalist
struct student {long st_id; char age; float GPA;} x, classa[30];
x.st_id, x.age, classa[1].GPA
struct bitstrct {bitfield1 : bitlnth1; ..... bitfieldn : bitlnthn} : bitwise structure
Shared : union : EQUIVALENCE
union [unioname] {char c; int i; float f;} a;
a.c, a.i, a.f
typeless : void
type array[n1][n2]....[nn]; : a[0][0]. a[0][1], a[0][2], ....., a[0][n2-1], a[1][0], a[1][1], a[1][2], ....., a[1][n2-1], a[2][0], .....
main() or subname(para.....)
Routine Variables;
{ Block Variables; ..... }
Arithmatic Operators : (+ -) (* / %(MOD))
Relational Operators : (< <= > >=) (== !=)
Logical Operators : &&(and) ||(or) !(not)
Bitwise Operators : ~(bitwise complement) &(bitwise AND) |(bitwise or) ^(bitwise XOR) <<(shift left) >>(shift right)
(aa<>n; : shift aa by n bits)
= += -= *= /= %= <<= >>= &= ^= |=
(a operator= c : a = a operator c)
Increment or decrement operator : ++ or -- : x=1; y=x++; (y=1,x=2) y=++x; (y=2,x=2)
rslt = expr1 ? expr2 : expr3 : if(expr1) rslt=expr2; else rslt=expr3;
while (expression) {..... statements ......}
for (expr1;expr2; expr3) {..... statements ......} : DO nn i=i1,in,id
expr1; while (expr2) {..... statements ..... expr3;}
do {..... statements .....} while (exprs)
if(exprs) {..... statements .....}
if(exprs) {..... statem1 .....} else {..... statem2 .....}
switch(exprs) {case valu1 : statem1 break; case valu2 : statem2 break; ..... case valun : statemn break; default : statemd break;}
break
continue
goto label1; label1: statement;
sizeof(item) : in <stdlib.h>
sizeof : memmory size of item in bytes
strlen : length of character string
strcpy : copy a character string
strcat : join two strings into one
strcmp : compare two character strings
strchr : position of a char in string
exit(n) : n=0 for normal termination
scanf("format", &item1, &item2, ......, &itemn)
printf("format", item1, item2, ......, itemn)
format : strings and %d %o %x %f %e %c %s
%5d %7.4f %9.3e
* : skip
\0 : null character
\a : alert (bell)
\b : back space
\f : form feed
\n : new line
\r : carriage return
\t : horizontal tab
\v : vertical tab
\\ : back slash
\" : double quotation mark
\' : single quotation mark
\ : line continue
\nnn : octal
\more
type sub1 (par1, par2)
{ ......... ;
....... ; }
type sub2 (par.....)
{ ......... ;
....... ; return; }
type sub3 (par......)
{ ......... ;
....... ; return expression; }
Standard functions ()
int getchar() int putchar()
char *gets(string) char *puts(string)
printf (fmt, par1, par2, ...) scanf (fmt, par1, par2, ...)
FILE *fopen(filename, filemode)
int fclose(ubitname)
int getc() int putc()
char *fgets() char fputs()
int ungets()
int fscanf() int fprint()
int fread() int fwrite()
fseek()
ftell()
FILE *unit, *fopen()
unit = fopen("filename", "r")
"r" "w" "a" "r+" "w+" "a+" ; (read-write)
"rb" "wb" "ab" ; (binary)
stdin :0: standard input file
stdout :1: standard output file
stderr :2: standard error file
fprintf(stdout, , , , ) = printf( , , , )
fscanf(stdin, , , , ) = scanf( , , , )
in math.h
double sin(double x)
cos
tan
asin
acos
atan
atan2(double x, double y) : atan(x/y)
double sinh(double x)
cosh
tanh
exp
log
log10
sqrt
power(double x, double y) : x^y
double ceil(double x)
double floor(double x)
int abs(int x)
int rand()
Compile and Link
cc -o filexec filename.c
g77 -o filexec filename.c