Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

ercis

Posted on 2000-02-24
6
191 Views
Last Modified: 2010-04-02
Please answer this for your points.
0
Comment
Question by:rkcth
  • 3
  • 3
6 Comments
 
LVL 22

Expert Comment

by:nietod
ID: 2556603
I believe this is for

http://www.experts-exchange.com/jsp/qShow.jsp?ta=cplusprog&qid=10299447 

correct?  (Always good to provide "justification".)
0
 
LVL 1

Accepted Solution

by:
ercis earned 50 total points
ID: 2559893
/***

this will do more: create 1x1 dot with specified color...
compile: gcc -Wall -s -o dot.cgi dot.c
and write in html:
 <img src="http://host.com/cgi-bin/dot.cgi?FF0000" width="50" height="5">

***/


#include <stdio.h>
#include <stdlib.h>

char x2c(char *what) {
   register char digit;
   digit = (what[0] >= 'A' ? ((what[0] & 0xdf) - 'A')+10 : (what[0] - '0'));
   digit *= 16;
   digit += (what[1] >= 'A' ? ((what[1] & 0xdf) - 'A')+10 : (what[1] - '0'));
   return(digit);
}

const unsigned char IMAGE_GIF1[] = {
   0x47, 0x49, 0x46, 0x38, 0x39, 0x61, 0x01, 0x00,
   0x01, 0x00, 0x80, 0xFF, 0x00, 0xFF, 0xFF, 0xFF };

const unsigned char IMAGE_GIF2[] = {
                     0x2C, 0x00, 0x00, 0x00, 0x00,
   0x01, 0x00, 0x01, 0x00, 0x00, 0x02, 0x02, 0x4C,
   0x01, 0x00, 0x3B };

int main(int argc, char *argv[])
{
   char *input, *p, *e;
   long l1 = sizeof(IMAGE_GIF1);
   long l2 = sizeof(IMAGE_GIF2);


   if( (p=getenv("REQUEST_METHOD")) && !strcmp(p, "GET") &&
       (p=getenv("QUERY_STRING")) && strlen(p) > 5 )
      input = p;
   else
      if(argc > 1 && strlen(argv[1]) > 5)  input = argv[1];
         else
            input = "ffffff";  // default = white

   printf("Content-type: image/gif\r\n");
   printf("Content-Length: %lu\r\n\r\n", l1 + 3 + l2);

   p = (char *)IMAGE_GIF1;
   e = p + l1;

   do
   {
     putchar(*p);
   }
   while (++p < e);

   putchar(x2c(input));
   putchar(x2c(input + 2));
   putchar(x2c(input + 4));

   p = (char *)IMAGE_GIF2;
   e = p + l2;

   do
   {
     putchar(*p);
   }
   while (++p < e);

   exit(0);
}

// nietod can make some optimizations :)
// maybe fwrite(IMAGE_GIF, sizeof(IMAGE_GIF), 1, stdout);
0
 
LVL 22

Expert Comment

by:nietod
ID: 2560921
Instead of

p = (char *)IMAGE_GIF1;
e = p + l1;

do
{
   putchar(*p);
}
while (++p < e);

I would just do

cout.write(IMAGE_GIF1,sizeof(IMAGE_GIF1));

it is simpler and likely to be faster.
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 1

Expert Comment

by:ercis
ID: 2562971
yes, but I'm talking about C, not C++
0
 
LVL 22

Expert Comment

by:nietod
ID: 2562994
But this is the C++ topic area.  We kill for less.  :-)
0
 
LVL 1

Expert Comment

by:ercis
ID: 2563462
nietod: sorry, I omited that :)
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question