views:

903

answers:

3
+2  A: 

That's a lot of questions!

You can generate JPEG and PNG files from C using libjpeg and libpng, respectively. (Yes, I'm dodging your GIF question on purpose. You don't need to do that; PNG is well-supported by mainstream browsers now and should be preferred. :-P)

Browsers generally only support JavaScript for client-side scripting. Using anything else will only destroy the portability of your webpages. Yes, like you say you can use plugins, but some people are averse to installing plugins, and others are behind corporate policies that don't allow such things.

Chris Jester-Young
thank u.I was just curious to know whether ther is any provision in c to do that?then how to do that? i need some example code. please find me one.once again thank u for ur response?
Manoj Doubts
+1  A: 

You can generate a web page from a C program by using the Common Gateway Interface (CGI). The C program is compiled and runs on the server, this is different from Javascript which runs on the browser.

You can also generate images via CGI too. Just set the content type appropriately, eg. image/jpeg for a JPEG image. You can use libjpeg to generate the actual image.


Here is an example C program to generate a page with a JPEG image:

#include <stdio.h>

main()
{
   char *pageTitle = "Look, a JPEG!";
   char *urlImage  = "/myimage.jpeg";

// Send HTTP header.
   printf("Content-type: text/html\r\n\r\n");

// Send the generated HTML.
   printf("<html><head><title>%s</title></head>\r\n"
          "<body>\r\n"
          "<h1>%s</h1>\r\n"
          "<img src=\"%s\">\r\n"
          "</body></html>\r\n",
          pageTitle, pageTitle, urlImage);
}
Adam Pierce
+1  A: 
  • To save jpeg files, you will need libjpeg. I am sure that there is a similar library for GIFs too.
  • C is not a scripting language. You cannot write scripts in C like in Javascript. You can write server-side code in with CGI if you dare but this is really not a good idea. There are a couple of better tools to write server side components, including C#/ASP.NET, Java, Python, Perl, Ruby (with Rails) or PHP. Even Coldfusion is better for webpages than C.
  • C is not an interpreted language. There is no browser that going to run your C code and I doubt there ever will be one, for millions of reasons. Also, there is no plugin for that. This is something really unfeasable. C is a great language for a lot of stuff, but the web is one of the areas where it's rarely used (except if you want to write a browser or a http server in C. But even for those tasks, C++ is usually better.) If you want client-side scripting in webpages, use Javascript. Some browsers will interpret VBScript too, but Javascript is the preferred browser scripting language.
DrJokepu