Globals Example

Description

This example shows using the global space at the top of a WebC file. When the first line of a WebC program is <?wc then instead of starting the page function WebC instead places this code into global space.

You can also see that C99 variables are used to declare the buff buffer in the middle of the function.

WebC Code

<?wc
#include <math.h>
#include <stdio.h>

double value=2;
?>
<!DOCTYPE HTML>
<html>
    <head>
        <title>Globals</title>
    </head>
    <body>
        <?wc
        char buff[100];
        sprintf(buff,"sqrt(%f)=%f",value,sqrt(value));
        wcecho(buff);
        ?>
    </body>
</html> 

C Code

#include "WCWebAPI.h"
#include <math.h>
#include <stdio.h>

double value=2;

void Page_SQRT(void)
{
    wcecho("<!DOCTYPE HTML>\n"
        "<html>\n"
        "   <head>\n"
        "       <title>Globals</title>\n"
        "   </head>\n"
        "   <body>\n");
    char buff[100];
    sprintf(buff,"sqrt(%f)=%f",value,sqrt(value));
    wcecho(buff);
    wcecho("   </body>\n"
        "</html>\n");
}

Output

<!DOCTYPE HTML>
<html>
   <head>
       <title>Globals</title>
   </head>
   <body>
       sqrt(2.000000)=1.414214
   </body>
</html>