Copy a program
Page 1 of 1 • Share
Copy a program
Write a program to copy its input to its output, replacing each tab by \t, each backspace by \b, and each backslash by \\. This makes tabs and backspaces visible in an unambiguous way.
Re: Copy a program
# include<iostream>
# include<string>
using namespace std;
main()
{char s[100];
gets(s);
int i=0;
while(s[i]!='\0')
{if(s[i]=='\t')
cout<<"\\t";
else if(s[i]=='\b')
cout<<"\\b";
else if(s[i]=='\\')
cout<<"\\\\";
else
cout<<s[i];
i++;
}
system("pause");
}
# include<string>
using namespace std;
main()
{char s[100];
gets(s);
int i=0;
while(s[i]!='\0')
{if(s[i]=='\t')
cout<<"\\t";
else if(s[i]=='\b')
cout<<"\\b";
else if(s[i]=='\\')
cout<<"\\\\";
else
cout<<s[i];
i++;
}
system("pause");
}
mnnit.rahul- Posts : 16
Join date : 2008-08-10
Read iT AgaiN ..
The ProGram given above doesn't solve the QuesTion..
the function "GETS" you are using cant read a BACKSPACE "\b". Right ?
It Writes to a Buffer after you Press EnTer .. So, no more doubts..
It needs a function thaT reads the CharacTer as soon as it is pressed..
You Guys remember getch() function in TURBO C,
Try 2 Find the Same .. in GCC ... and POST it here..
the function "GETS" you are using cant read a BACKSPACE "\b". Right ?

It Writes to a Buffer after you Press EnTer .. So, no more doubts..
It needs a function thaT reads the CharacTer as soon as it is pressed..
You Guys remember getch() function in TURBO C,
Try 2 Find the Same .. in GCC ... and POST it here..

Dee2306- Posts : 7
Join date : 2008-08-12
Age : 31
Re: Copy a program
getchar() would fulfill the requirement.u need to stop at getchar()=EOF 

ankurgutpa- Posts : 44
Join date : 2008-08-10
Age : 32
Location : Tandon 72
Naaah .. !!
getchar() too works on char by char but starts Read!nG .. after the Enter is Pressed..
So, getchar() is not the one i am asking for .
So, getchar() is not the one i am asking for .

Dee2306- Posts : 7
Join date : 2008-08-12
Age : 31
Re: Copy a program
the backspace can be trapped using curses
keypad() will do the trick.....
more @ http://www.daniweb.com/forums/thread112789.html
keypad() will do the trick.....
more @ http://www.daniweb.com/forums/thread112789.html
shivang- Posts : 22
Join date : 2008-08-11
Age : 30
Location : Tondon 174
dee
use redirection and not console like ./a.out<input.txt and this is the standard way
..
lekin D lde sirf tere liye ye function dhoondha waise mujhe bhi nahin pata chal raha ki saala ho kya raha hai
int mygetch ( void )
{
int ch;
struct termios oldt, newt;
tcgetattr ( STDIN_FILENO, &oldt );
newt = oldt;
newt.c_lflag &= ~( ICANON | ECHO );
tcsetattr ( STDIN_FILENO, TCSANOW, &newt );
ch = getchar();
tcsetattr ( STDIN_FILENO, TCSANOW, &oldt );
return ch;
}
include necessary files before compiling this program like sys/types,unistd etc etc

..
lekin D lde sirf tere liye ye function dhoondha waise mujhe bhi nahin pata chal raha ki saala ho kya raha hai
int mygetch ( void )
{
int ch;
struct termios oldt, newt;
tcgetattr ( STDIN_FILENO, &oldt );
newt = oldt;
newt.c_lflag &= ~( ICANON | ECHO );
tcsetattr ( STDIN_FILENO, TCSANOW, &newt );
ch = getchar();
tcsetattr ( STDIN_FILENO, TCSANOW, &oldt );
return ch;
}
include necessary files before compiling this program like sys/types,unistd etc etc

ankurgutpa- Posts : 44
Join date : 2008-08-10
Age : 32
Location : Tandon 72
@ANKUR
abe kya likha hai kuch samjha bhi de
kaunsi language likhi hai?
curses.h maine include karne ki koshish kari thi but wo g++ mien ho nayi rahi thi
kaunsi language likhi hai?
curses.h maine include karne ki koshish kari thi but wo g++ mien ho nayi rahi thi
mnnit.rahul- Posts : 16
Join date : 2008-08-10
@ankur
saale aisa prog to daal jo samajh mei aaye.....
ya phir link hi de de jahan se liya ai.....kuch pata to chale....

ya phir link hi de de jahan se liya ai.....kuch pata to chale....


shivang- Posts : 22
Join date : 2008-08-11
Age : 30
Location : Tondon 174
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum