Solved

ercis

Posted on 2000-02-24
6
187 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 Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
C++ finding a sting in a char* string from a text file 3 93
C++ Language error 28 149
Best book to learn C++ 4 55
c++ syntax question 9 36
Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

743 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

12 Experts available now in Live!

Get 1:1 Help Now