CSS in CGI with C

You can easily use CSS while using CGI in C language. Here is a small demo.

hello.c file:

int main()
printf("Content-type: text/html\n\n");
printf("<html><head><link href=\"../mycss.css\" rel=\"stylesheet\" type=\"text/css\"></head>");
return 0;

mycss.css file:

color: white;
font-size: 2.30em;

mycss.css file is in ~/public_html folder and hello.c file is in ~/public_html/cgi-bin folder in my case.

Note:- Don’t place css file in cgi-bin file.  If you place, it will not work.

Compile it and run:

priyanka@priyanka:~/public_html/cgi-bin$ gcc hello.c
priyanka@priyanka:~/public_html/cgi-bin$ ./a.out
Content-type: text/html

<html><head><link href="../mycss.css" rel="stylesheet" type="text/css"></head><body><h1>Hello</h1></body></html>

Open the browser and type in URL  localhost/~username/cgi-bin/a.out

In my case, it is: localhost/~priyanka/cgi-bin/a.out

Output is:

cgi c

Thats all.


About Priyanka Kapoor

Simple, Hardworking & friendly.....
This entry was posted in Uncategorized. Bookmark the permalink.

One Response to CSS in CGI with C

  1. This helped me! thanks.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s