Turbo C/C++ and other junk compilers help, discussions and queries here

sid_ashok

Broken In
Hello Brothers and sisters
this the right thread for me.

Ask me what ever u wana learn.

Any one intrested in graphics in C++ or graphics in Qbasic consult me.

In graphic in c++ u can use your mouse in the program.
and u can alse create window style menus.
U can click on them.
U can draw any thing like ,any thing 3D or 2D( all in C++)
 

Maverick340

Ambassador of Buzz
Code:
#include<iostream.h>
#include<string.h>
#include<stdio.h>

void main(){
char str[30];
cout<<"Enter a line  : ";
gets(str);
for(int i=0;i!='\0';i++)
	{
	if( str[i]=='d'||str[i]=='D')
	 {
	 str[i]='*';
	 str[i+1]='*';
	 str[i+2]='*';
	 }}
cout<<str;
}

This according to loads of you may work.It is right according to the Sumita arora book(class11th).
But wen u try it in TC3.0 or TC 4.5 its dosent work!
Error: the null charcter is a '#' and not '\0'.
I spent i hout jus cuz of this problem!
 

anubhav_har

In the zone
amanwannalearn said:
Code:
#include<iostream.h>
#include<string.h>
#include<stdio.h>

void main(){
char str[30];
cout<<"Enter a line  : ";
gets(str);
for(int i=0;i!='\0';i++)
	{
	if( str[i]=='d'||str[i]=='D')
	 {
	 str[i]='*';
	 str[i+1]='*';
	 str[i+2]='*';
	 }}
cout<<str;
}

This according to loads of you may work.It is right according to the Sumita arora book(class11th).
But wen u try it in TC3.0 or TC 4.5 its dosent work!
Error: the null charcter is a '#' and not '\0'.
I spent i hout jus cuz of this problem!

'\0' works fine in both TC 3 and 4 and after you said this i tested it... i don;t know why it is not working on your pc
 

Maverick340

Ambassador of Buzz
amanwannalearn said:
Code:
void main(){
char str[30];
cout<<"Enter a line  : ";
gets(str);
for(int i=0;[b]i!='\0[/b]';i++)
	{
	if( str[i]=='d'||str[i]=='D')

Oh gawd!i am such a dooofus!
the correct code is str[i]!='\0'
and not str[i]!='\0'
When you give str[i]!='\0' it runs the loop 35 times cuz the ACSII code of '\0' is 35.
sorry 
	 :oops:
 

anubhav_har

In the zone
mako_123 said:
can any one please post the program of Tower Of Hanoi .
Code:
#include<stdio.h>
#include<conio.h>
int LDisc[8],RDisc[8],CDisc[8],lc=0,rc=0,cc=0,nod;
void transfer(int n,char from,char to,char temp,int i);
void Display(int a[],int count,int col);
void main()
{
	int i;
	clrscr();
	printf("Welcome to Tower Of Hanoi Problem!\n");
	printf("How Many Disk ?");
	scanf("%d",&nod);
	for(i=0;i<nod;i++)
	LDisc[lc++]=nod-i;
	clrscr();
	gotoxy(2,2);
	Display(LDisc,lc,2);
	getch();
	transfer(nod,'L','R','C',1);
}
	
	void transfer(int n,char from,char to,char temp,int i)
	{
		if( n > 0 )
		{
			transfer(n-1,from,temp,to,i+1);
			clrscr();
			printf("Move Disk %d from %c to %c \n",n,from,to);
			switch(from)
			{
				case 'L': if(lc)
					  lc--; break;
				case 'R': if(rc)
					  rc--;break;
				case 'C': if(cc)
					  cc--;break;
			}
			switch(to)
			{
				case 'L': LDisc[lc++]=n;
					  break;
				case 'R':RDisc[rc++]=n;
					 break;
				case 'C':CDisc[cc++]=n;
					 break;
			}	
			gotoxy(2,2);
			Display(LDisc,lc,2);
			gotoxy(27,2);
			Display(RDisc,rc,27);
			gotoxy(52,2);
			Display(CDisc,cc,52);
		    	printf("\n");
			printf("Press Any Key For Next Move ");
			getch();
			transfer(n-1,temp,to,from,i+1);
	}
	return;
}
	
void Display(int a[],int count,int col)
{
	int i,j,k;
	for(i=0;i<nod;i++)
	{
		if(count+i ==	nod)
		{
			for(j=nod;j > a[count-1]-1;j--)
			printf(" ");
			for(j=0;j < a[count-1];j++)
			printf("-");
			printf("|");
			for(j=0;j<a[count-1];j++)
			printf("-");
			for(j=nod;j > a[count-1]-1;j--)
			printf(" ");
			count--;
		}
		else
		{
			for(j=0;j<=nod;j++)
			printf(" ");
			printf("|");
			for(j=0;j<=nod;j++)
			printf(" ");
		}
		k=wherey();
		gotoxy(col,k+1);
	}
}
This should work
 

QwertyManiac

Commander in Chief
what do u mean by that, there only one thing up, the sky et all... :p

if u dont understand wat we r talkin, plz read the whole thread...
 

ApoCalypse

Broken In
@The Incredible
Tower of Hanoi?...

its a simple puzzle
consider 3 pegs a, b, c

let peg a have n disks of varying sizes arranged in descending order from bottom...largest at the base..

c is the destination peg

transfer all disks from a to c subject to the foll conditions...

1) you can use b as an auxillary peg
2) only one disk can be transferred at a time
3) never can a smaller disk be atop a larger one

simple enough??
the implementation is simple as well...think about it
hint: (use recursion to simplify it)
 
Top Bottom