QwertyManiac
Commander in Chief
oops, sorry never thot of it,
EDITED !
Thn for that mistake point anubhav !
EDITED !
Thn for that mistake point anubhav !
its not a problem mohit... its just there are so many ppl posting that you take someone for soemone else....mohit sharma said:sorry anubhav u were mistakenly taken as incredible !
#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;
}
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!
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:
mako_123 said:can any one please post the program of Tower Of Hanoi .
#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);
}
}