This program generates captcha, a captcha is a random code generated using some algorithm. We will use random function in our code. These are used in typing tutors and in website to check whether a human is operating on a website.

C programming code

[pastacode lang=”c” manual=”%23include%3Cstdlib.h%3E%0A%23include%3Cdos.h%3E%0A%23include%3Cgraphics.h%3E%0A%20%0Amain()%0A%7B%0A%20%20%20int%20i%20%3D%200%2C%20key%2C%20num%2C%20midx%2C%20gd%20%3D%20DETECT%2C%20gm%3B%0A%20%20%20char%20a%5B10%5D%3B%0A%20%0A%20%20%20initgraph(%26gd%2C%26gm%2C%22C%3A%5C%5CTC%5C%5CBGI%22)%3B%0A%20%0A%20%20%20midx%20%3D%20getmaxx()%2F2%3B%0A%20%0A%20%20%20settextstyle(SCRIPT_FONT%2CHORIZ_DIR%2C5)%3B%0A%20%20%20settextjustify(CENTER_TEXT%2CCENTER_TEXT)%3B%0A%20%20%20setcolor(GREEN)%3B%0A%20%20%20outtextxy(midx%2C20%2C%22CAPTCHA%22)%3B%0A%20%20%20settextstyle(SCRIPT_FONT%2CHORIZ_DIR%2C2)%3B%0A%20%20%20outtextxy(midx%2C125%2C%22Press%20any%20key%20to%20change%20the%20generated%20random%20code%20%5C%22captcha%5C%22%22)%3B%0A%20%20%20outtextxy(midx%2C150%2C%22Press%20escape%20key%20to%20exit…%22)%3B%0A%20%0A%20%20%20setcolor(WHITE)%3B%0A%20%20%20setviewport(100%2C200%2C600%2C400%2C1)%3B%0A%20%20%20setcolor(RED)%3B%0A%20%20%20randomize()%3B%0A%20%0A%20%20%20while(1)%0A%20%20%20%7B%0A%20%20%20%20%20%20while(i%3C6)%0A%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20num%20%3D%20random(3)%3B%0A%20%0A%20%20%20%20%20%20%20%20%20if%20(%20num%20%3D%3D%200%20)%0A%20%20%20%20%20%20%20%20%20%20%20%20a%5Bi%5D%20%3D%2065%20%2B%20random(26)%3B%20%20%20%20%20%2F*%2065%20is%20the%20ASCII%20value%20of%20A%20*%2F%0A%20%20%20%20%20%20%20%20%20else%20if%20(%20num%20%3D%3D%201)%0A%20%20%20%20%20%20%20%20%20%20%20%20a%5Bi%5D%20%3D%2097%20%2B%20random(26)%3B%20%20%20%20%20%2F*%2097%20is%20the%20ASCII%20value%20of%20a%20*%2F%0A%20%20%20%20%20%20%20%20%20else%0A%20%20%20%20%20%20%20%20%20%20%20%20a%5Bi%5D%20%3D%2048%20%2B%20random(10)%3B%20%20%20%20%20%2F*%2048%20is%20the%20ASCII%20value%20of%200%20*%2F%0A%20%20%20%20%20%20%20%20%20i%2B%2B%3B%0A%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20a%5Bi%5D%20%3D%20’%5C0’%3B%0A%20%20%20%20%20%20outtextxy(210%2C100%2Ca)%3B%0A%20%20%20%20%20%20key%20%3D%20getch()%3B%0A%20%0A%20%20%20%20%20%20if(%20key%20%3D%3D%2027%20)%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%2F*%20escape%20key*%2F%0A%20%20%20%20%20%20%20%20%20exit(0)%3B%0A%20%20%20%20%20%20clearviewport()%3B%0A%20%20%20%20%20%20i%20%3D%200%3B%0A%20%20%20%7D%0A%7D” message=”” highlight=”” provider=”manual”/] [ad type=”banner”]

Categorized in: