Copy a program

Go down

Copy a program

Post  Admin on Sun Aug 10, 2008 9:05 am

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.

Admin
Admin

Posts : 39
Join date : 2008-08-03

View user profile http://computerclub09mnnit.forumotion.net

Back to top Go down

Re: Copy a program

Post  mnnit.rahul on Mon Aug 11, 2008 3:38 am

# 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");
}

mnnit.rahul

Posts : 16
Join date : 2008-08-10

View user profile

Back to top Go down

Read iT AgaiN ..

Post  Dee2306 on Tue Aug 12, 2008 10:30 am

The ProGram given above doesn't solve the QuesTion..

the function "GETS" you are using cant read a BACKSPACE "\b". Right ? pirat
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.. Laughing
avatar
Dee2306

Posts : 7
Join date : 2008-08-12
Age : 30

View user profile

Back to top Go down

Re: Copy a program

Post  ankurgutpa on Tue Aug 12, 2008 11:42 am

getchar() would fulfill the requirement.u need to stop at getchar()=EOF cheers
avatar
ankurgutpa

Posts : 44
Join date : 2008-08-10
Age : 31
Location : Tandon 72

View user profile

Back to top Go down

Naaah .. !!

Post  Dee2306 on Tue Aug 12, 2008 1:05 pm

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 . Mad
avatar
Dee2306

Posts : 7
Join date : 2008-08-12
Age : 30

View user profile

Back to top Go down

Re: Copy a program

Post  shivang on Tue Aug 12, 2008 3:17 pm

the backspace can be trapped using curses
keypad() will do the trick.....
more @ http://www.daniweb.com/forums/thread112789.html
avatar
shivang

Posts : 22
Join date : 2008-08-11
Age : 29
Location : Tondon 174

View user profile

Back to top Go down

dee

Post  ankurgutpa on Tue Aug 12, 2008 3:25 pm

use redirection and not console like ./a.out<input.txt and this is the standard way Twisted Evil
..
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 cheers
avatar
ankurgutpa

Posts : 44
Join date : 2008-08-10
Age : 31
Location : Tandon 72

View user profile

Back to top Go down

@ANKUR

Post  mnnit.rahul on Wed Aug 13, 2008 10:44 am

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

mnnit.rahul

Posts : 16
Join date : 2008-08-10

View user profile

Back to top Go down

@ankur

Post  shivang on Wed Aug 13, 2008 12:17 pm

saale aisa prog to daal jo samajh mei aaye.....
ya phir link hi de de jahan se liya ai.....kuch pata to chale.... Evil or Very Mad Laughing
avatar
shivang

Posts : 22
Join date : 2008-08-11
Age : 29
Location : Tondon 174

View user profile

Back to top Go down

Re: Copy a program

Post  Sponsored content


Sponsored content


Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum