?
Solved

ercis

Posted on 2000-02-24
6
Medium Priority
?
194 Views
Last Modified: 2010-04-02
Please answer this for your points.
0
Comment
Question by:rkcth
[X]
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
  • 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 200 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
Suggested Courses
Course of the Month13 days, 6 hours left to enroll

801 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