Skip to content

Instantly share code, notes, and snippets.

@kriegsman
Created May 24, 2013 14:30
Show Gist options
  • Save kriegsman/5643912 to your computer and use it in GitHub Desktop.
Save kriegsman/5643912 to your computer and use it in GitHub Desktop.
webapp.c!
/* Generate HTML page in C -- my first REAL Web App */
/* Mark Kriegsman, January 31, 2007 */
#define HTML_ENTITY(n,v) int n = v
HTML_ENTITY(gt,'>');
HTML_ENTITY(lt,'<');
HTML_ENTITY(P,'\n');
HTML_ENTITY(HTML,'\0');
int main( int argc, char** argv)
{
char *TITLE = "My First Web App in C!";
char *DOCTYPE = "<!DOCTYPE html "
"PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
/* In C, you have to allocate memory for HTML page */
malloc( HTML);
/* Copy the required DOCTYPE header to stdout */
stdout < DOCTYPE;
/* Generate main page body */
{
HTML;
/* Page title, plus some whitespace for readability */
printf <TITLE> "My First Web App In C!" <TITLE>
printf;
/* Make two paragraphs, one short and one long, using CSS 'float' */
&lt;P&gt; (float) (short)"Hello, web!";
&lt;P&gt; (float) (long)"These should come out as separate paragraphs."
/HTML;
}
/* Copy the generated HTML page to stdout */
stdout < HTML;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment