C and C++ Computer Graphics

C graphic program to generate Captcha code

Description:

  1. Use turbo C++ editor to write the program
  2. Give the path of BGI, where the BGI stored in your computer in initgraph function like initgraph(&gd,&gm,”C:\\Turboc3\\BGI”);
  3. Write the logic for generating random captcha code.

Using functions of graphics.h in Turbo C compiler you can make graphics programs, animations, projects, and games. You can draw circles, lines, rectangles, bars and many other geometrical figures.

Captcha is a random code generated using some algorithm.Here is use of random function in this code.
[wp_ad_camp_1]

#include<stdlib.h>
#include<dos.h>
#include<graphics.h>
main()
{
int i = 0, key, num, midx, gd = DETECT, gm;
char a[10];
initgraph(&gd,&gm,"C:\\Turboc3\\BGI");
midx = getmaxx()/2;
settextstyle(SCRIPT_FONT,HORIZ_DIR,5);
settextjustify(CENTER_TEXT,CENTER_TEXT);
setcolor(GREEN);
outtextxy(midx,20,"CAPTCHA");
settextstyle(SCRIPT_FONT,HORIZ_DIR,2);
outtextxy(midx,125,"Press any KEYBOARD KEY to change the generated random code \"captcha\"");
outtextxy(midx,150,"Press escape key to exit...");
setcolor(WHITE);
setviewport(100,200,600,400,1);
setcolor(RED);
randomize();
while(1)
{
while(i<6)
{
num = random(3);
if ( num == 0 )
a[i] = 65 + random(26); /* 65 -the ASCII value of A */
else if ( num == 1)
a[i] = 97 + random(26); /* 97 - the ASCII value of a */
else
a[i] = 48 + random(10); /* 48 -the ASCII value of 0 */
i++;
}
a[i] = '\0';
outtextxy(210,100,a);
key = getch();
if( key == 27 ) /* escape key used*/
exit(0);
clearviewport();
i = 0;
}
}

[wp_ad_camp_1]
C graphic program to generate Captcha code

Leave a comment

Your email address will not be published. Required fields are marked *