Solved

ercis

Posted on 2000-02-24
6
189 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
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 user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

919 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now