Sambar Server Documentation
|
CScript Quick Overview of C |
|
When used in an ASP page, the code might look like:
|
The result of executing the above ASP page or program is that the characters ``Hello World'' are printed out.
A C program contains functions and variables. The functions specify the tasks to be performed by the program. The ``main'' function establishes the overall logic of the code. It is normally kept short and calls different functions to perform the necessary sub-tasks. All C programs must have a ``main'' function. CScript ASP pages are a bit different; CScript wraps the ASP page in an implicit ``main'' function.
The above code calls printf, an output function from the I/O (input/output) library (a complete list of libraries and their functions can be found in the System Administration Show CScript Functions forms). The printf line prints the message ``Hello World'' on ``stdout'' (the output stream corresponding to the terminal or client browser in which you run the code); ``\n'' prints a ``new line'' character, which brings the cursor onto the next line.
The ``;'' denotes the end of a statement. Blocks of statements are put in braces {...}, as in the definition of functions. All C statements are defined in free format, i.e., with no specified layout or column assignment. Whitespace (tabs or spaces) is never significant, except inside quotes as part of a character string. The following program would produce exactly the same result as our earlier example:
<HTML><BODY>
main(){printf("Hello World\n");}
The following is a slightly longer program that adds three integers and prints their sum.
main()
{
int a, b, c, sum;
a = 1;
b = 2;
c = 3;
sum = a + b + c;
printf("sum is %d\n", sum);
}
© 2001 Sambar Technologies. All rights reserved. Terms of Use.