Solve the given C Puzzle

Status
Not open for further replies.

Faun

Wahahaha~!
Staff member
a_k_s_h_a_y said:
Execute in Turbo C only
You must first save this file in TC directory ONLY save as .C file and then run it in TC
if you save as .CPP then it won't execute


so some graphics in C

Code:
/* Execute in Turbo C only 
You must first save this file in TC directory as NAME.C only and then run it in TC
if you save as .CPP then it won't execute   */

#include <graphics.h>
#include <dos.h>
#include <conio.h>
main()
{
    int gd=DETECT,gm,button,x,y,x2,y2,i;
    char a;
    x=0;y=0;

    initgraph(&gd,&gm,"");
    setcolor(2);
    setfillstyle(SOLID_FILL,BLACK);
    outtextxy(50,400,"Keep holding Space For Tom to Chase, Any key to Exit ");
    outtextxy(50,430,"hell with the rules this was made by me long back now just edited little ");
    outtextxy(50,450,"i have to study for VTU bye and btw All the best Mr Very Rude Adi");

    for(x=0;x<480;x++)
    {
    outtextxy(x,y,"Tom  Jerry");
    a=getch();
    bar(x,y,x+79,y+10);
    if(a!=' ') exit(0);
    }

    for(x=480;x>0;x--)
    {
    outtextxy(x,y+30,"Tom  Jerry");
    a=getch();
    bar(x,y,x+79,y+50);
    if(a!=' ') exit(0);
    }
    while(!kbhit());
}
lol..these quizzies are nuts:))*farm3.static.flickr.com/2286/2107305542_22d75ef21a_o.png
 

a_k_s_h_a_y

Dreaming
T159 said:
lol..these quizzies are nuts:))*farm3.static.flickr.com/2286/2107305542_22d75ef21a_o.png
yeah i did not give into it much ..
just wrote back the program with slight changes of the version that i already had

its basically Dos Program with DOS.H and i tried compiling it in borland latest but i get errors .. hell lots .. don't know why.

Graphics in C is outdated i think.. but that's what i used for My Text Editor and Graphics Editor Projects in 3rd SEM .. i mean i am using .. still in 3rd Sem lol

i really don't know why newly available compiler fails in this .. !! after all its just C.. about KBHIT function its ok i know its defined in DOS.h
and i could have used sleep() to get out put exactly as need but let it be space bar . i think its cool
 

Faun

Wahahaha~!
Staff member
a_k_s_h_a_y said:
yeah i did not give into it much ..
just wrote back the program with slight changes of the version that i already had

its basically Dos Program with DOS.H and i tried compiling it in borland latest but i get errors .. hell lots .. don't know why.

Graphics in C is outdated i think.. but that's what i used for My Text Editor and Graphics Editor Projects in 3rd SEM .. i mean i am using .. still in 3rd Sem lol

i really don't know why newly avaible compiler fails in this .. !! after all its just C.. about KBHIT function its ok i know its defined in DOS
and i could have used sleep() to get out put exactly as need but let it be space bar . i think its cool

turbo c graphics libraries are not ANSI C compliant.
I hated so much using it till 3rd year.
 

a_k_s_h_a_y

Dreaming
^^ then how do i go about with graphics in C ?

my big text editor and graphics editor projects that i wrote in TC are all waste or what ??
 

Faun

Wahahaha~!
Staff member
a_k_s_h_a_y said:
^^ then how do i go about with graphics in C ?

my big text editor and graphics editor projects that i wrote in TC are all waste or what ??
nothing is waste, all serves for some purpose.
U will need it during ur engg (curse the old syllabus)

Just dont make it mainstream, there are other tools to create graphics.
 

Faun

Wahahaha~!
Staff member
a_k_s_h_a_y said:
for example ??
no not directx and windows API .. i am trying to stay away from it for some time now
other then that maybe
am not aware abt other tools in C, and its hihgly unlikely that u will be allowed to use anyhing other than gcc and turbo c in college. So better stick to old ways for the time being.

i hav learned making UI using JAVA and XUL.
 

Yamaraj

The Lord of Death
C doesn't care about graphics, sound or input devices. You must use external libraries and/or system API for that kind of a program.
 

Faun

Wahahaha~!
Staff member
Yamaraj said:
C doesn't care about graphics, sound or input devices. You must use external libraries and/or system API for that kind of a program.
yeah those 3rd party libraries*farm3.static.flickr.com/2192/2107308402_d580fcfc62_o.png
 

anantkhaitan

Burning Bright
Gr8 thread...
My solution to Problem no. 10
Code:
#include<conio.h>
#include<stdio.h>
#include<dos.h>
void main()
{
int x=1,y=1,d=1;
char a[]=" Tom  Jerry  ";
while(!kbhit())
     {
     gotoxy(x,y);
     printf(a);
     delay(50);
     x+=d;
     if(x==81&&y==1&&d==1){x=1;y=2;}
     if(x==0&&y==2&&d==-1){x=80;y=1;}
     if(x==69&&y==2&&d==1){d=-1;a[4]=32;a[12]=2;}
     if(x==1&&y==1&&d==-1){d=1;a[4]=2;a[12]=32;}
     }
}

Note: String a[ ] contains that similey Alt+2 after Tom
And guys I don't have a TC++ compiler so this program was tested by dry run GCC doesn't support conio
 
Last edited:

Pathik

Google Bot
T159 said:
am not aware abt other tools in C, and its hihgly unlikely that u will be allowed to use anyhing other than gcc and turbo c in college. So better stick to old ways for the time being.

i hav learned making UI using JAVA and XUL.
But isnt XUL used mainly only in firefox extensions??
btw r u also in engg??
 

Faun

Wahahaha~!
Staff member
pathiks said:
But isnt XUL used mainly only in firefox extensions??
btw r u also in engg??
nope XUL is used in songbird player.(its platform independent)

And its all based on XML (the mega player of web based applications), XML can be used to make almost everything.

Everything is getting web based.

yeah am in engg.
 
OP
A

adi007

Youngling
*gigasmilies.googlepages.com/68.gifsorry,i just forgot to specify another imporatant rule

Rules
No user defined functions..
only stdio.h,conio.h and string.h are allowed
no gotoxy()

now try..*gigasmilies.googlepages.com/yes.gif
and let me give u a hint that it has nothing to do with graphics...*gigasmilies.googlepages.com/16.gif
 
Last edited:

anantkhaitan

Burning Bright
^^ are yaar.. I was using dos.h only for delay().. ok if you don't want it then..
Code:
#include<conio.h>
#include<stdio.h>
void main()
{
int x=1,y=1,d=1;
char a[]=" Tom  Jerry  ";
while(!kbhit())
     {
     gotoxy(x,y);
     printf(a);
     for(long i=0;i<99999;i++); // Time delay loop
     x+=d;
     if(x==81&&y==1&&d==1){x=1;y=2;}
     if(x==0&&y==2&&d==-1){x=80;y=1;}
     if(x==69&&y==2&&d==1){d=-1;a[4]=32;a[12]=2;}
     if(x==1&&y==1&&d==-1){d=1;a[4]=2;a[12]=32;}
     }
}

Not using graphics is not a hint but its obvious.. :p
 
Last edited:
OP
A

adi007

Youngling
first thing there should be smiley..
second jerry should chase tom with a smiley..
third no gotoxy(sorry i didn't specified it in the beginning)...

i will add more rules..
wait till tommorow..
I think i made a mess of this puzzle...*gigasmilies.googlepages.com/39.gif
 

anantkhaitan

Burning Bright
^^
Brother do you want to me to write the program exactly as you have written.. A program can be written in hundred of ways, and now you start adding rules..Its not that I cannot write the program without using gotoxy(), but again I will write a program and you will say: "You cannot use this or that"..First of all be clear with your problem. And as far as the competition/contest/(whateva it is) is concern I am seeing that I am the only participant..

adi said:
first thing there should be smiley..
second jerry should chase tom with a smiley..
Have you compiled the program..?? and for the smiley check what I have written earlier #131:
String a[ ] contains that similey (Alt+2) after Tom
Now you can take this much of pain atleast because i don't have Turbo C++ with me.. rather i don't have DOS with me..
 
OP
A

adi007

Youngling
i will be clear with my rules tommorow and that will be final..*gigasmilies.googlepages.com/yes.gif
sorry for the trouble..*gigasmilies.googlepages.com/63.gif
i am accesing net from my college and i have no internet connection in my home..
so it is not possible to check ur program..

instead of smiley use some char such as '#'
 
Last edited:

anantkhaitan

Burning Bright
Ok brother bring your rules tomorrow.. here I bring my program (without gotoxy());
Code:
#include<conio.h>
#include<stdio.h>
void main()
{
int s=0,d=1,j;
char a[]="Tom#  Jerry ";
while(!kbhit())
     {
     clrscr();
     for(j=0;j<s;j++)printf(" ");
     printf(a);
     for(long i=0;i<99999;i++);
     s+=d;
     if(s==149&&d==1){d=-1;a[3]=32;a[11]=35;}
     if(s==0&&d==-1){d=1;a[3]=35;a[11]=32;}
     }
}
 
OP
A

adi007

Youngling
final set of rules


allowed header files -->stdio.h,conio.h&string.h
no gotoxy(),clreol(),delline(),kbhit()
maximum of 4 variables
no user defined functions
the printf statements shouldn't be empty i.e printf(" ") not allowed

if ur compiler doesn't support smiley then some char such as '#'
 
Status
Not open for further replies.
Top Bottom