Solve the given C Puzzle

Status
Not open for further replies.
OP
A

adi007

Youngling
anuj919 said:
I think it is next to impossible to solve the puzzle 9 without using getch/getche (Which r in "conio.h ") because without it one can't read sentence 'word by word'

So please can we use getch/getche?
what....:shock::shock::shock:
getch() and getche() comes under stdio.h :confused::confused:
wait let me confirm it.....
 
Last edited:

Yamaraj

The Lord of Death
adi007 said:
confirmed...
getche() and getch() comes under stdio.h(tested in TC++ 3.0)..
If you cannot tell ANSI/ISO standard C from a system-dependent implementation (i.e., Turbo C++), you ought to invest more time in learning the language rather than posting non-standard, useless, and tricky puzzles here.
 

fun2sh

Pawned!... Beyond GODLIKE
adi007 said:
confirmed...
getche() and getch() comes under stdio.h(tested in TC++ 3.0)..
no adi. it cant be!:shocked: i checked it again now n its comes in conio.h only!!n i hav the same tc as urs. even in the help file of tc its mentioned conio.h!!
 
OP
A

adi007

Youngling
hmmm..:confused:
i created the solution program by using conio.h for clrscr()
then i removed clrscr() and #include<conio.h>
then i made some modifications to the solution program and compiled it...
It worked fine..
I tested the program by using both getch() and getche() without using conio.h and it worked....:confused::confused:
wait ..
I will confirm it later by creating the program from the scratch......
 
Last edited:

Yamaraj

The Lord of Death
What is there to confirm? You should not have skipped studying the C Standard Library while you were busy mastering the syntax.

Non-standard and system/implementation dependent functions like getch(), getche() or clrscr() CANNOT reside in a standard header like stdio.h.
 
OP
A

adi007

Youngling
I accept my fault....
I am extermely sorry for the mistake...
I referred the help documentation and some books and found that getch() ,getche() comes under conio.h...
So rules are modified
One can use getch(),getche() but must not use clrscr()
here are the modified rules

Rules
1.No user defined functions..
2.No usage of clrscr()
3.No header file other than stdio.h and conio.h should be used.
4.No * symbol in the whole program

Now i let me explain why i commited such a big mistake..

I am using TC++ 3.0 for the past 3 years and have never used conio.h for getch() and getche().:shock:So i thought these 2 comes under stdio.h
The following program works fine in my TC

Code:
#include<stdio.h>
void main()
{
clrscr();
printf("Press any key\n");
getche();
getch();
}

and even this works fine
Code:
void main()
{
clrscr();
printf("Press any key\n");
getche();
getch();
}

I have made the vedio file and will upload and give the link within this week...
 
Last edited:

QwertyManiac

Commander in Chief
Yeah how does stdio.h cover clrscr as your code example claims so? Use standard code mate, and allow a wider population to join.
 

anuj919

Broken In
I got the answer again:D :D :D :D


But yes Adithya is true:idea: , the program works fine without including "conio.h"
& can anyone tell me that how this happens in Turbo C++ 3.0 :confused: :confused:

Here is the answer:


Code:
#include<stdio.h>
#include<conio.h>

void main()
{
	char b[999];
	int i=0,j=0;
	char c;

	printf("Enter the String\n");
	while((c=getche())!='')
	{
		if(c==' ')
		{
			for(j=0;j<=i;j++)
				printf("\b");
			for(j=i-1;j>=0;j--)
				printf("%c",b[j]);
			printf(" ");
			i=0;
		}
		else
			b[i++]=c;
	}
	printf("\nHave a Nice Day!");
	getch();
}
 
OP
A

adi007

Youngling
^^Very good :):)
puzzle 9 solved

anuj919 said:
But yes Adithya is true:idea: , the program works fine without including "conio.h"
& can anyone tell me that how this happens in Turbo C++ 3.0 :confused: :confused:
^^I had told this already but nobody believed me :sad::sad:
Thanks for supporting me...:D:D:D
New puzzle tommorow at 12:15 PM

fun2sh said:
has some settings been change of ur TC++ compiler??
^^nope..

QwertyManiac said:
Yeah how does stdio.h cover clrscr as your code example claims so? Use standard code mate, and allow a wider population to join.
^^ i will be careful from now on...
 
Last edited:

Yamaraj

The Lord of Death
anuj919 said:
But yes Adithya is true:idea: , the program works fine without including "conio.h"
& can anyone tell me that how this happens in Turbo C++ 3.0 :confused: :confused:


adi007 said:
^^I had told this already but nobody believed me :sad::sad:
Thanks for supporting me...:D:D:D
I wonder if it's of any use talking sense into people these days. Turbo C++ is NOT C or even C++. Either ask mods to change the title from "C puzzle" to "Turbo C++ puzzles", or spend some time reading the standard ANSI/ISO C and post accordingly.

People still using TC++ 3.0 should be hanged till death. Tell that to your instructor/professor.
 
OP
A

adi007

Youngling
Yamaraj said:
I wonder if it's of any use talking sense into people these days. Turbo C++ is NOT C or even C++. Either ask mods to change the title from "C puzzle" to "Turbo C++ puzzles", or spend some time reading the standard ANSI/ISO C and post accordingly.

People still using TC++ 3.0 should be hanged till death. Tell that to your instructor/professor.
sorry Yamaraj..
I will take care that this will not happen again...
Will follow strict ANSI/ISO C standards from now on...
By the way which c compiler u use..?

Sorry for not giving puzzle 10 yeterday.Will give puzzle 10 tommorow...
 

Yamaraj

The Lord of Death
No need to be sorry. I only want you and others to get better at programming. I use many compilers actually - GCC (On Linux and Cygwin), MinGW (GCC for Win32), Visual C++ 2008 Express Edition, Sun C and C++ on Solaris etc.

If you want a decent ANSI/ISO conforming C compiler for Windows, try Pelles C - *www.smorgasbordet.com/pellesc/ or MinGW.

Things like unbuffered I/O, non-standards functions like clrscr() and getch()/getche() are entirely system or implementation dependent, and likely to distract a potential learner from the path of becoming a real good programmer. In fact, it's the code readability, re-usability and portability that you should be more concerned about.
 
OP
A

adi007

Youngling
adi007 said:
Hi! I am Adithya U,17 year old Engineering Student(IT) from Hassan,Karnataka

*farm3.static.flickr.com/2052/2086499468_1f153310e7_o.gif​

Currently you are witnessing C puzzle 10



First,let me state the rules in this thread:
1.Please do not give suggestions or hints.Specify the modified program only.
2.Before posting the program make sure it's working in the way i want.


Here is the 10th C puzzle



write a c program in which tom will chase jerry for 2 lines and then jerry bounce back and will chase tom to the begining..

confused..*gigasmilies.googlepages.com/39.gif*gigasmilies.googlepages.com/39.gif

here is the output that i expect..

*farm3.static.flickr.com/2351/2085714733_b87446cf37_o.gif

Note:I captured the output using camtassia but it could not capture it correctly..Even then the real output will be similar to this..



Note :Specify your modified program along with the answer

Awards gallary:
Puzzles solved :9
me (If no one gets the solution then points will be for me) 2
saurabh kakkar 2
fun2sh 2
anuj919 2
eggman 1
nigthtcrawler 1

Leading:saurabh kakkar,fun2sh,anuj919 and myself

Puzzle 10 added thread updated...

Yamaraj said:
If you want a decent ANSI/ISO conforming C compiler for Windows, try Pelles C - *www.smorgasbordet.com/pellesc/ or MinGW.
^^Thanks Yamaraj for the link...have downloaded Pelles C.It's nice.*gigasmilies.googlepages.com/4.gif
 
Last edited:

QwertyManiac

Commander in Chief
Two lines as in two physical lines or prompt/terminal width dependent? Cause I see your 'Jerry' trickling down to the 2nd line character by character.
 

a_k_s_h_a_y

Dreaming
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());
}
 
Last edited:
Status
Not open for further replies.
Top Bottom